Advertisement
Foxscotch

fixed frick

Jan 15th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Locked topic quotes
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        http://forum.blockland.us/index.php?topic=*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. var mainUrl = 'http://forum.blockland.us/';
  12. var quoteImageUrl = mainUrl + 'Themes/Blockland/images/english/quote.gif';
  13.  
  14. function getStatus() {
  15.     var status = {};
  16.     var statusImages = document.querySelectorAll('.titlebg > td > img');
  17.    
  18.     if (statusImages[statusImages.length - 1].src.endsWith('locked.gif')) {
  19.         status.locked = true;
  20.     }
  21.     if (statusImages.length > 1) {
  22.         status.poll = true;
  23.         if (statusImages[0].src.endsWith('locked.gif')) {
  24.             status.pollLocked = true;
  25.         }
  26.     }
  27.    
  28.     return status;
  29. }
  30. var status = getStatus();
  31.  
  32. function getSession() {
  33.     var logout = document.querySelector('img[alt="Logout"]').parentElement;
  34.     return logout.href.split('=')[2];
  35. }
  36. var sessId = getSession();
  37.  
  38. function addTextBox() {
  39.     var container = document.createElement('div');
  40.     container.id = 'locked-topic-container';
  41.    
  42.     var textArea = document.createElement('textarea');
  43.     textArea.id = 'locked-topic-textbox';
  44.    
  45.     var copyButton = document.createElement('button');
  46.     copyButton.id = 'locked-topic-copy';
  47.    
  48.     textArea.style.display = 'block';
  49.     textArea.style.margin = 'auto';
  50.     textArea.style.width = '25%';
  51.     textArea.style.height = '150px';
  52.    
  53.     copyButton.addEventListener('click', function () {
  54.         textArea.select();
  55.         var copied = document.execCommand('copy');
  56.         copied ? console.log('Copied') : console.log('Not copied');
  57.     });
  58.    
  59.     var breaks = document.getElementsByTagName('br');
  60.     breaks[breaks.length - 2].insertAdjacentElement('afterend', textArea);
  61.     textArea.insertAdjacentElement('beforebegin', copyButton);
  62. }
  63.  
  64. function getQuote(link) {
  65.     window.ajax_indicator(1);
  66.     var xhr = new XMLHttpRequest();
  67.     var quote;
  68.  
  69.     xhr.onload = function () {
  70.         xml = xhr.responseXML;
  71.         quote = xml.getElementsByTagName('quote')[0].textContent;
  72.  
  73.         document.getElementById('locked-topic-textbox').value += quote;
  74.  
  75.         window.ajax_indicator(0);
  76.     };
  77.  
  78.     xhr.open('GET', `http://forum.blockland.us/index.php?action=quotefast;quote=${link.dataset.messageId};sesc=${sessId};xml`);
  79.     xhr.send();
  80. }
  81.  
  82. function addQuoteButtons() {
  83.     var quoteDestinations = document.querySelectorAll('td[height="20"]:not([width])');
  84.    
  85.     for (var i = 0; i < quoteDestinations.length; i++) {
  86.         var link = document.createElement('a');
  87.         link.href = "#locked-topic-textbox";
  88.        
  89.         var quoteImg = document.createElement('img');
  90.         quoteImg.src = quoteImageUrl;
  91.         quoteImg.alt = 'Reply with quote';
  92.         quoteImg.border = '0';
  93.        
  94.         link.appendChild(quoteImg);
  95.         quoteDestinations[i].appendChild(link);
  96.        
  97.         var msgId = quoteDestinations[i].parentElement.querySelector('div').id.split('_')[1];
  98.         link.dataset.messageId = msgId;
  99.  
  100.         link.addEventListener('click', getQuote.bind(null, link));
  101.     }
  102. }
  103.  
  104. if (status.locked) {
  105.     console.log('Topic is locked');
  106.     addTextBox();
  107.     addQuoteButtons();
  108. }
  109.  
  110. if (status.poll) { console.log('Topic has poll'); }
  111. if (status.pollLocked) { console.log('Poll is locked'); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement