Created
December 11, 2018 13:04
-
-
Save mmodrow/3e8762b26333b3ff8c83f4bd5be48226 to your computer and use it in GitHub Desktop.
Non-Evented Download-Links on 9gag
This file contains hidden or 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 Non-Evented Download-Link on 9gag | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Adds an anchor to every 9gag-Post, that has no events attached to it. | |
// @author https://gist.github.com/mmodrow | |
// @match https://9gag.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function addDownloadIcons(parentNode){ | |
var articles = parentNode.querySelectorAll("article"); | |
articles = Array.prototype.slice.call(articles); | |
for (var i = 0; i < articles.length; i++){ | |
if(!!articles[i]){ | |
addDownloadIcon(articles[i]); | |
} | |
} | |
} | |
function addDownloadIcon(article){ | |
if(!article){ | |
return null; | |
} | |
var oldLink = article.querySelector(".js-tamper-customDownload"); | |
if(!!oldLink){ | |
oldLink.remove(); | |
} | |
var header = article.querySelector("header"); | |
if(!header){ | |
return null; | |
} | |
var url = header.querySelector("a[data-entry-id]").href; | |
var image = document.createElement("img"); | |
image.src = "https://image.flaticon.com/icons/svg/25/25407.svg"; | |
image.style = "height: 25px;"; | |
var anchor = document.createElement("a"); | |
anchor.className = "js-tamper-customDownload"; | |
anchor.href = url; | |
anchor.style = "position: absolute; right: 0; top: 0;" | |
anchor.appendChild(image); | |
header.appendChild(anchor); | |
} | |
var mainSection = document.querySelector(".main-wrap>section"); | |
addDownloadIcons(mainSection); | |
mainSection.addEventListener( 'DOMNodeInserted', function ( event ) { | |
if( event.target.parentNode.id === 'list-view-2' ) { | |
addDownloadIcons(event.target); | |
}; | |
}, false ); | |
var img = document.createElement("img"); | |
img.src = "https://image.flaticon.com/icons/svg/25/25429.svg"; | |
img.style="position: fixed; top: 10px; right: 10px; width: 50px; background-color: white; padding: 10px; z-index: 999; border-radius: 5px; cursor:pointer;"; | |
img.addEventListener("click", function(){ | |
addDownloadIcons(mainSection); | |
}); | |
document.body.appendChild(img); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment