Last active
June 6, 2021 01:04
-
-
Save rf5860/bc7d255b9a6e07d854449e4fd7c1e289 to your computer and use it in GitHub Desktop.
[Keyboard Maestro Forum Improvements] Removes search blurbs, adds a clipboard ot copy code, and provides a menu for all linked sripts in the thread #UserScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Keyboard Maestro Forum Improvements | |
// @version 0.2 | |
// @description Removes search blurbs, adds a clipboard ot copy code, and provides a menu for all linked sripts in the thread | |
// @require http://code.jquery.com/jquery-1.12.4.js | |
// @require http://code.jquery.com/ui/1.12.1/jquery-ui.js | |
// @author rjf89 | |
// @match *://forum.keyboardmaestro.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function createIcon() { | |
const i = document.createElement('i'); | |
i.classList.add('fa'); | |
i.classList.add('fa-clipboard'); | |
i.onclick = (event) => { | |
$(event.target).effect( "bounce", "slow" ); | |
document.execCommand('copy'); | |
}; | |
i.addEventListener('copy', function(event) { | |
event.preventDefault(); | |
event.clipboardData.setData('text/plain', event.currentTarget.parentElement.textContent); | |
}); | |
return i; | |
} | |
[...document.querySelectorAll('.blurb.container')].forEach(blurb => blurb.remove()); | |
[...document.querySelectorAll('pre>code')] | |
.map(code => code.parentElement) | |
.forEach(pre => pre.insertBefore(createIcon(), pre.firstChild)); | |
var parentDiv = document.createElement('div'); | |
var leftDiv = document.createElement('div'); | |
[...document.querySelectorAll('a')] | |
.filter(a => a.href.endsWith('.kmmacros') || a.href.endsWith('.zip')) | |
.map(a => a.cloneNode(true)) | |
.forEach(a => { leftDiv.appendChild(a); leftDiv.appendChild(document.createElement('br')); } ); | |
parentDiv.appendChild(leftDiv); | |
var rightDiv = document.createElement('div'); | |
rightDiv.style = 'padding-left: 2em'; | |
[...document.querySelectorAll('div.topic-body')] | |
.map(div => [...div.querySelectorAll('a')]) | |
.filter(a => !!a.href) | |
.filter(a => !a.href.contains('/u/')) | |
.filter(a => !a.href.contains('users')) | |
.filter(a => !a.href.endsWith('.png')) | |
.filter(a => !a.href.endsWith('.gif')) | |
.reduce((xs, ys) => [...xs, ...ys], []) | |
.map(a => a.cloneNode(true)) | |
.forEach(a => { rightDiv.appendChild(a); rightDiv.appendChild(document.createElement('br')); } ); | |
parentDiv.appendChild(rightDiv); | |
document.querySelector('div#topic-title').appendChild(parentDiv); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment