Advertisement
Foxscotch

Locked Topic Quotes (SMF v2; non-working)

Aug 29th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Locked topic quotes
  3. // @namespace    https://foxscotch.us/
  4. // @version      1.3
  5. // @description  Show quote buttons on locked topics
  6. // @author       Foxscotch
  7. // @match        https://forum.blockland.us/index.php?topic=*
  8. // @grant        none
  9. // ==/UserScript==
  10. 'use strict';
  11.  
  12. var mainUrl = 'https://forum.blockland.us/index.php?';
  13.  
  14. function getQuote(link) {
  15.     window.ajax_indicator(true);
  16.     var xhr = new XMLHttpRequest();
  17.     var quote;
  18.  
  19.     xhr.onload = function () {
  20.         var xml = xhr.responseXML;
  21.         quote = xml.getElementsByTagName('quote')[0].textContent;
  22.  
  23.         console.log(xml);
  24.  
  25.         document.getElementById('locked-topic-textbox').value += quote;
  26.  
  27.         window.ajax_indicator(false);
  28.     };
  29.  
  30.     xhr.open('GET', mainUrl + `action=quotefast;quote=${link.dataset.messageId};xml`);
  31.     xhr.send();
  32. }
  33.  
  34. function addTextBox() {
  35.     var container = document.createElement('div');
  36.     container.id = 'locked-topic-container';
  37.  
  38.     var textArea = document.createElement('textarea');
  39.     textArea.id = 'locked-topic-textbox';
  40.  
  41.     var copyButton = document.createElement('button');
  42.     copyButton.id = 'locked-topic-copy';
  43.     copyButton.textContent = "Copy to clipboard";
  44.  
  45.     container.style.margin = 'auto';
  46.     container.style.width = '25%';
  47.  
  48.     textArea.style.display = 'block';
  49.     textArea.style.height = '150px';
  50.     textArea.style.width = "100%";
  51.  
  52.     copyButton.addEventListener('click', function () {
  53.         textArea.select();
  54.         var copied = document.execCommand('copy');
  55.         copied ? console.log('Copied') : console.log('Not copied');
  56.     });
  57.  
  58.     var nav = document.getElementsByClassName('navigate_section')[1];
  59.     nav.parentElement.insertBefore(container, nav);
  60.     container.appendChild(copyButton);
  61.     container.appendChild(textArea);
  62. }
  63.  
  64. function addQuoteButtons() {
  65.     var msgIdRegex = /.+msg(\d+)/;
  66.     var destinations = document.querySelectorAll('div.flow_hidden');
  67.  
  68.     for (var dest of destinations) {
  69.         var ul = document.createElement('ul');
  70.         ul.classList.add('reset', 'smalltext', 'quickbuttons');
  71.  
  72.         var li = document.createElement('li');
  73.         li.classList.add('quote_button');
  74.         ul.appendChild(li);
  75.  
  76.         var a = document.createElement('a');
  77.         a.href = '#locked-topic-textbox';
  78.         a.textContent = 'Quote';
  79.         li.appendChild(a);
  80.  
  81.         dest.appendChild(ul);
  82.  
  83.         var msgIdLink = dest.querySelector('a').href;
  84.         a.dataset.messageId = msgIdLink.match(msgIdRegex)[1];
  85.  
  86.         a.addEventListener('click', getQuote.bind(null, a));
  87.     }
  88. }
  89.  
  90. var topic_image = document.querySelectorAll('h3.catbg > img')[0];
  91. if (topic_image && topic_image.src.includes('locked')) {
  92.     addTextBox();
  93.     addQuoteButtons();
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement