Last active
December 1, 2018 17:09
-
-
Save boisei0/bf7e5f071bf2042f8300b238a92d4f97 to your computer and use it in GitHub Desktop.
Tampermonkey script to use with https://www.slackdeletron.com
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 Slackdeletron file nuke | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Nuke all files in any slackdeletron search... | |
// @author You | |
// @match https://www.slackdeletron.com/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var timeoutStorageVar; | |
var mutationObserverTargetNode = document.querySelector('.Header__Meta'); | |
var observerOptions = { | |
childList: true, | |
subtree: true, | |
} | |
function insertNukeButtonCallback(mutationList, observer) { | |
mutationList.forEach((mutation) => { | |
if (mutation.type === 'childList') { | |
if (mutation.removedNodes.length !== 0) { | |
if (document.getElementById('NukeButton') === null) { | |
// Good to go | |
var nukeButton = document.createElement('button'); | |
nukeButton.appendChild(document.createTextNode('Nuke all files (slowly)')); | |
nukeButton.id = 'NukeButon'; | |
nukeButton.setAttribute('style', 'background: red; color: white'); | |
nukeButton.setAttribute('class', 'Button Button__Large'); | |
nukeButton.addEventListener('click', function() { | |
// alert('hi'); | |
delFile(); | |
}); | |
document.getElementsByClassName('Button Button__Large')[0].parentNode.appendChild(nukeButton); | |
} | |
observer.disconnect(); | |
return; | |
} | |
} | |
}); | |
} | |
var mutationObserver = new MutationObserver(insertNukeButtonCallback); | |
mutationObserver.observe(mutationObserverTargetNode, observerOptions); | |
// Source: https://github.com/drewminns/slackdeletron/issues/36#issuecomment-395613555 | |
function delFile() { | |
// first check if we need to do another search | |
var list = document.getElementsByTagName('h2') | |
for (var i = 0; i < list.length; i++) { | |
if (list[i] && list[i].innerText && list[i].innerText == 'Zap! Deleted!') { | |
document.getElementsByClassName('Button Button__Large')[0].click() | |
} | |
} | |
// look for a delete button | |
var button = document.getElementsByClassName('File__Button')[0] | |
if (button) { | |
button.click() | |
} | |
else { | |
clearTimeout(timeoutStorageVar); | |
return; | |
} | |
var interval = 1000 + (Math.random() * 2000) | |
timeoutStorageVar = setTimeout(delFile, interval) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: