Created
March 4, 2015 21:33
-
-
Save Heolink/4cb877fc8ae76f0fc57d to your computer and use it in GitHub Desktop.
HabitRpg background changer le background pour teste
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 HabitRpg background | |
// @namespace HabitRpgBackground | |
// @include https://habitrpg.com/* | |
// @version 1 | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
function exec(fn) { | |
var script = document.createElement('script'); | |
script.setAttribute('type', 'application/javascript'); | |
script.textContent = '(' + fn + ')();'; | |
document.body.appendChild(script); // run the script | |
document.body.removeChild(script); // clean up | |
} | |
window.addEventListener('load', function () { | |
// script injection | |
exec(function () { | |
cl = function (d) { | |
console.log(d) | |
} | |
var arrayMethods = Object.getOwnPropertyNames(Array.prototype); | |
arrayMethods.forEach(attachArrayMethodsToNodeList); | |
function attachArrayMethodsToNodeList(methodName) | |
{ | |
NodeList.prototype[methodName] = Array.prototype[methodName]; | |
}; | |
var backgroundsExist = setInterval(function () { | |
var e = document.querySelector('.background-locked') | |
if(e) { | |
clearInterval(backgroundsExist); | |
var heroBox = document.querySelector('.herobox'); | |
var backgrounds = document.querySelectorAll('.customize-option') | |
var count = 0; | |
backgrounds.forEach(function (background) { | |
count++; | |
var backgroundName = /background_[a-z_]+/.exec(background.className)[0]; | |
var preview = document.createElement('a'); | |
preview.innerHTML = 'Preview'; | |
preview.href = '#'; | |
preview.style.display = 'block'; | |
preview.style.margin = '0px'; | |
preview.style.padding = '0px'; | |
preview.style.width = '100px'; | |
var ctn = document.createElement('div'); | |
ctn.style.width = '170px'; | |
ctn.style.float = 'left'; | |
ctn.style.margin = '10px'; | |
ctn.appendChild(preview) | |
ctn.appendChild(background.cloneNode(true)) | |
var clear = document.createElement('div'); | |
clear.style.clear = 'both'; | |
background.parentNode.replaceChild(ctn, background) | |
if(count == 3) { | |
ctn.parentNode.insertBefore(clear, ctn.nextSibling); | |
count = 0; | |
} | |
//background.parentNode.insertBefore(preview, background) | |
preview.onclick = function(e) { | |
e.preventDefault() | |
heroBox.className = heroBox.className.replace(/noBackgroundImage/, '').replace(/background_[a-z_]+/, '').replace(/background_/, '') | |
heroBox.className = heroBox.className + ' ' + backgroundName | |
}; | |
}); | |
} | |
}, 100); | |
}); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment