Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Locked topic quotes
- // @namespace https://foxscotch.us/
- // @version 1.3
- // @description Show quote buttons on locked topics
- // @author Foxscotch
- // @match https://forum.blockland.us/index.php?topic=*
- // @grant none
- // ==/UserScript==
- 'use strict';
- var mainUrl = 'https://forum.blockland.us/index.php?';
- function getQuote(link) {
- window.ajax_indicator(true);
- var xhr = new XMLHttpRequest();
- var quote;
- xhr.onload = function () {
- var xml = xhr.responseXML;
- quote = xml.getElementsByTagName('quote')[0].textContent;
- console.log(xml);
- document.getElementById('locked-topic-textbox').value += quote;
- window.ajax_indicator(false);
- };
- xhr.open('GET', mainUrl + `action=quotefast;quote=${link.dataset.messageId};xml`);
- xhr.send();
- }
- function addTextBox() {
- var container = document.createElement('div');
- container.id = 'locked-topic-container';
- var textArea = document.createElement('textarea');
- textArea.id = 'locked-topic-textbox';
- var copyButton = document.createElement('button');
- copyButton.id = 'locked-topic-copy';
- copyButton.textContent = "Copy to clipboard";
- container.style.margin = 'auto';
- container.style.width = '25%';
- textArea.style.display = 'block';
- textArea.style.height = '150px';
- textArea.style.width = "100%";
- copyButton.addEventListener('click', function () {
- textArea.select();
- var copied = document.execCommand('copy');
- copied ? console.log('Copied') : console.log('Not copied');
- });
- var nav = document.getElementsByClassName('navigate_section')[1];
- nav.parentElement.insertBefore(container, nav);
- container.appendChild(copyButton);
- container.appendChild(textArea);
- }
- function addQuoteButtons() {
- var msgIdRegex = /.+msg(\d+)/;
- var destinations = document.querySelectorAll('div.flow_hidden');
- for (var dest of destinations) {
- var ul = document.createElement('ul');
- ul.classList.add('reset', 'smalltext', 'quickbuttons');
- var li = document.createElement('li');
- li.classList.add('quote_button');
- ul.appendChild(li);
- var a = document.createElement('a');
- a.href = '#locked-topic-textbox';
- a.textContent = 'Quote';
- li.appendChild(a);
- dest.appendChild(ul);
- var msgIdLink = dest.querySelector('a').href;
- a.dataset.messageId = msgIdLink.match(msgIdRegex)[1];
- a.addEventListener('click', getQuote.bind(null, a));
- }
- }
- var topic_image = document.querySelectorAll('h3.catbg > img')[0];
- if (topic_image && topic_image.src.includes('locked')) {
- addTextBox();
- addQuoteButtons();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement