Created
August 28, 2014 18:33
-
-
Save SkySkimmer/5b974beac0867eb56766 to your computer and use it in GitHub Desktop.
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 WrongEveryTime image insert | |
// @description Add image after clicked link on wrongeverytime.com | |
// @author SkySkimmer | |
// @version 1.1 | |
// @history 1.1 Insert images button | |
// @history 1.0 Initial functionality | |
// @license GPL version 3 | |
// @namespace SkySkimmer | |
// @include http://wrongeverytime.com/* | |
// ==/UserScript== | |
if (typeof String.prototype.startsWith != 'function') { | |
String.prototype.startsWith = function (prefix) { | |
if (this.length < prefix.length) | |
return false; | |
for (var i = prefix.length - 1; (i >= 0) && (this[i] === prefix[i]); --i); | |
return i < 0; | |
}; | |
} | |
function insertAfter(newNode, referenceNode) { | |
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); | |
} | |
var links = document.getElementsByTagName('a'); | |
for (var i = 0; i < links.length; i++) | |
{ | |
if (links[i].href.startsWith('http://i.imgur.com/')) | |
{ | |
links[i].onclick = function () { | |
var img = document.createElement('img'); | |
img.className = 'size-full'; | |
img.src = this.href; | |
img.style.display = 'block'; | |
insertAfter(img, this); | |
this.onclick = null; | |
return false; }; | |
} | |
} | |
var cat = document.getElementById('menu-categories'); | |
var cell = document.createElement('li'); | |
cell.className = 'menu-item menu-item-type-post_type menu-item-object-page'; | |
var input = document.createElement('button'); | |
input.type = 'button'; | |
input.appendChild(document.createTextNode('Insert images')); | |
input.onclick = function () { | |
this.onclick = null; | |
for(var i=0; i<links.length; i++) | |
{ | |
if (links[i].href.startsWith('http://i.imgur.com/')) | |
{ | |
links[i].onclick = null; | |
var img = document.createElement('img'); | |
img.className = 'size-full'; | |
img.src = links[i].href; | |
img.style.display = 'block'; | |
insertAfter(img, links[i]); | |
} | |
} | |
this.innerHTML += ' (done)'; | |
}; | |
cell.appendChild(input); | |
cat.appendChild(cell); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment