Advertisement
Foxscotch

frick

Jan 15th, 2016
86
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 addQuoteButtons() {
  65.     var quoteDestinations = document.querySelectorAll('td[height="20"]:not([width])');
  66.    
  67.     for (var i = 0; i < quoteDestinations.length; i++) {
  68.         var link = document.createElement('a');
  69.         link.href = "#locked-topic-textbox";
  70.        
  71.         var quoteImg = document.createElement('img');
  72.         quoteImg.src = quoteImageUrl;
  73.         quoteImg.alt = 'Reply with quote';
  74.         quoteImg.border = '0';
  75.        
  76.         link.appendChild(quoteImg);
  77.         quoteDestinations[i].appendChild(link);
  78.        
  79.         var msgId = quoteDestinations[i].parentElement.querySelector('div').id.split('_')[1];
  80.         link.dataset.messageId = msgId;
  81.  
  82.         link.addEventListener('click', function () {
  83.             window.ajax_indicator(1);
  84.             var xhr = new XMLHttpRequest();
  85.             var quote;
  86.            
  87.             xhr.onload = function () {
  88.                 xml = xhr.responseXML;
  89.                 quote = xml.getElementsByTagName('quote')[0].textContent;
  90.  
  91.                 document.getElementById('locked-topic-textbox').value += quote;
  92.                
  93.                 window.ajax_indicator(0);
  94.             };
  95.            
  96.             xhr.open('GET', `http://forum.blockland.us/index.php?action=quotefast;quote=${link.dataset.messageId};sesc=${sessId};xml`);
  97.             xhr.send();
  98.         });
  99.     }
  100. }
  101.  
  102. if (status.locked) {
  103.     console.log('Topic is locked');
  104.     addTextBox();
  105.     addQuoteButtons();
  106. }
  107.  
  108. if (status.poll) { console.log('Topic has poll'); }
  109. if (status.pollLocked) { console.log('Poll is locked'); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement