Bold Reply

Bedre reply-funktion på bold.dk

  1. // ==UserScript==
  2. // @name Bold Reply
  3. // @namespace http://quovadis.dk/
  4. // @description Bedre reply-funktion på bold.dk
  5. // @include https://www.bold.dk/snak/index.php?action=reply&id=*
  6. // @include https://www.bold.dk/snak/index.php?action=thread&id=*
  7. // @icon https://www.bold.dk/favicon.ico
  8. // @version 1.0.2
  9. // ==/UserScript==
  10.  
  11. console.log('Bold Reply');
  12.  
  13. function bold_reply_main() {
  14. var url = document.location;
  15. console.log(url);
  16. if (/thread/.test(url)) {
  17. addAuthor();
  18. }
  19. if (/reply/.test(url)) {
  20. addQuote();
  21. }
  22. }
  23.  
  24. function addAuthor() {
  25. $('a.tekst').each(function (idx) {
  26. var href = $(this).attr('href');
  27. if (/reply/.test(href)) {
  28. var author = $(this).parent().parent().find('a > b').html();
  29. console.log(author);
  30. $(this).attr('href', href + '&author=' + encodeURIComponent(author));
  31. }
  32. });
  33. }
  34.  
  35. function getAuthor() {
  36. var author = '';
  37. try {
  38. author = decodeURIComponent(/author=(.*)$/.exec(document.location)[1]);
  39. }
  40. catch (e) {
  41. console.warn('No author found');
  42. }
  43. return author;
  44. }
  45.  
  46. function addQuote() {
  47. var post = '[quote][b]' + getAuthor() + '[/b]: ';
  48. var quote = $('div.col1 > div').first().html();
  49. quote = quote.replace(/<strong>.*<\/strong>/, '');
  50. quote = quote.replace(/<(i|blockquote)>/gm, '[i]');
  51. quote = quote.replace(/<\/i>/gm, '[/i]');
  52. quote = quote.replace(/<\/blockquote>/gm, '[/i]\n\n');
  53. quote = quote.replace(/<b>/gm, '[b]');
  54. quote = quote.replace(/<\/b>/gm, '[/b]');
  55. quote = quote.replace(/<br>/gm, '\n');
  56. $('#post').val(post + quote.trim() + '[/quote]');
  57. }
  58.  
  59. bold_reply_main();