// ==UserScript== // @name Quote in locked threads // @namespace https://bitcointalk.org // @version 0.1 // @description Save headache when quoting from locked threads // @author minifrij // @match https://bitcointalk.org/index.php?topic=* // @require https://code.jquery.com/jquery-3.4.1.slim.min.js // @grant none // ==/UserScript== function post2BB(input){ //This deletes all quotes in the post //I do this because I can't be arsed with them. //https://www.youtube.com/watch?v=Jne9t8sHpUc //Maybe it's something I'll fix later, if no one else has a go //Don't hold your breath though input = input.replace(/
.*?<\/div>/g, ''); input = input.replace(/
.*<\/div>/g, ''); //FFS (For Formatting Sake) let output = "\n"; //Match and replace some basic tags input = input.replace(/
/g, "\n"); input = input.replace(/
/g, "[hr]"); input = input.replace(/BTC<\/span>/g, "[btc]"); input = input.replace(/([\S|\s]*?)<\/b>/gm, "[b]$1[/b]"); input = input.replace(/([\S|\s]*?)<\/i>/gm, "[i]$1[/i]"); input = input.replace(/([\S|\s]*?)<\/span>/gm, "[u]$1[/u]"); input = input.replace(/([\S|\s]*?)<\/del>/gm, "[s]$1[/s]"); //I felt like a genius when I figured this out. I'm not very good with regex //If someone tries to make a link go over several lines this will break, but what sort of a barbarian would do that? //Is that even possible? input = input.replace(/(.*?)<\/a>/g, '[url=$1]$2[/url]'); //I'll reason with you, this doesn't really work too good //If the layout of your post is broken, this part is probably why //However, so long as you're not quoting the post of a crazed lunatic (or minerjones) you're probably alright input = input.replace(/([\S|\s]*?)<\/span>/g, '[size=$1]$2[/size]'); input = input.replace(/([\S|\s]*?)<\/span>/g, '[glow=$1,2,300]$2[/glow]'); input = input.replace(/([\S|\s]*?)<\/span>/g, '[color=$1]$2[/color]'); //Deal with the images and the image proxy //Sometimes this doesn't properly match an image. I don't know why. images = input.match(//gm); console.log(images); if(images !== null){ for(let i=0;i/g.exec(images[i]); input = input.replace(images[i], '[img]' + decodeURIComponent(image[1]) + '[/img]') } } //Lazily delete any other tags that are left behind input = input.replace(/<.*?>|<\/.*?>/g, ''); //Add the cooked parsed-a to the pan output += input; //Season it output += "\n"; //Plate it return output; } (function() { 'use strict'; //This script uses jQuery because I didn't feel like spending 2 weeks writing this thing //Feel free to remove it if you really want to, I wish you the best of luck if($('a[href^="https://bitcointalk.org/index.php?action=logout;"]').length == 0){ return; } let topicIcon = $('img[src^="https://bitcointalk.org/Themes/custom1/images/topic/"]'); if(topicIcon.length == 0 || !topicIcon.attr('src').includes('locked')){ return; } //If you've got this far then you're both logged in and on a locked topic. Way to go, champ! //Create the quote button let quoteButton = 'Reply with quote'; $('div[id^="ignmsgbttns"]').prepend(quoteButton); //Make said quote button do things $('.td_headerandpost').on('click', '.fake-quote', function(){ let quoteBB = ''; let postArea = $(this).parents('.td_headerandpost'); //Get all the necessary stuff for building a quote let quoteUser = postArea.prev().find('a[title^="View the profile of"]').text().trim(); let quoteLink = postArea.find('.subject a').attr('href').split('?')[1].trim(); let quoteDate = Math.round(new Date(postArea.find('.subject').next().text()).getTime()/1000); //If the post has been edited, it'll run this if(quoteDate.toString() == 'NaN'){ quoteDate = Math.round(new Date(postArea.find('.subject').next().find('span:first-child').text()).getTime()/1000); } //Build the quote quoteBB += '[quote author=' + quoteUser + ' link=' + quoteLink + ' date=' + quoteDate + ']'; //Enjoy your meal. quoteBB += post2BB(postArea.find('.post').html()); quoteBB += '[/quote]'; //Create a textarea, make it fill the post and put the quote inside let quoteArea = ''; //Shove it in place of the post postArea.find('.post').attr('style', 'position:relative;overflow:hidden;min-height:200px;'); postArea.find('.post').append(quoteArea); }); })();