Last active
December 15, 2015 09:08
-
-
Save kissarat/5235704 to your computer and use it in GitHub Desktop.
for last-minute.de
rough copy
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 PriceConverter | |
// @author Тарас Лабяк | |
// @namespace Alim | |
// @version 1.0 | |
// @description Збільшує ціни на 20% (ціни діляться на 0.8) | |
// @encoding utf-8 | |
// ==/UserScript== | |
// atch http://*last-minute.de/ | |
// atch http://*traveltainment.de/ | |
// http://wiki.plemiona.pl/wiki/Poradnik:Skrypty | |
var regex = /[0-9]+/; | |
var priceNodes = []; | |
function pushNodes(obj) { | |
switch (obj.constructor) { | |
case String.prototype.constructor: | |
this.current = document.getElementsByClassName(obj); | |
break; | |
case NodeList.constructor: | |
this.current = obj; | |
break; | |
default: | |
return false; | |
} | |
if (this.current.length > 0) | |
console.log(obj + ' ' + this.current.length); | |
return priceNodes.push(this.current); | |
} | |
pushNodes.prototype.current = []; | |
Array.prototype.pushNodes = function(obj) { | |
if (obj instanceof Array || obj instanceof NodeList && obj.length > 0) { | |
for(var i=0; i<obj.length; i++) | |
this.push(obj[i]); | |
return true; | |
} | |
else if(obj instanceof Node) { | |
this.push(obj); | |
return true; | |
} | |
return false; | |
} | |
function getParentElementByTagName(element, name) { | |
name = name.toUpperCase(); | |
for(var parent = element; | |
(parent = parent.parentElement) && !name.equals(parent.tagName);); | |
return parent; | |
} | |
function convert() { | |
if (pushNodes('terRe')) | |
pushNodes('tervakpreis') | |
else if (pushNodes('preisbuchung')) { | |
var elems = getParentElementByTagName(pushNodes.current, 'tbody'); | |
for (var i=0; i<2;) | |
if(elems[i] instanceof Element) { | |
priceNodes.pushNodes(elems[i]); | |
i++; | |
} | |
} | |
else | |
pushNodes('preis'); | |
for (var i=0; i<priceNodes.length; i++) { | |
var priceNode = priceNodes[i]; | |
var priceString = priceNode.innerHTML; | |
if (!regex.test(priceString)) | |
continue; | |
var price = regex.exec(priceString)[0]; | |
price = eval(price); | |
price = price/0.8; | |
price = Math.ceil(price); | |
priceNode.innerHTML = priceString.replace(regex, price); | |
} | |
} | |
window.safeEvent('onload'); | |
window.onload = convert; | |
//TrT_onL = convert; | |
/*Object.defineProperty(window, 'TrT_onL', { | |
set: function (value) { | |
alert('hello'); | |
}, | |
get: function () { | |
return convert; | |
} | |
}) | |
var old_onload = onload; | |
_onloads = []; | |
delete onload; | |
_onload = function(event) { | |
alert(_onloads.length); | |
for(var i=0; i<_onloads.length; i++) | |
(_onloads[i])(event); | |
} | |
//_onloads.push(old_onload); | |
Object.defineProperty(window, 'onload', { | |
set: function(callback) { | |
if (callback && !_onloads.contains(callback)) { | |
_onloads.push(callback); | |
console.log('onload callback: ' | |
+ (callback.name ? callback.name : callback)); | |
} | |
}, | |
get: function() { | |
console.log('onload'); | |
return _onload; | |
} | |
}); | |
if ('function' == typeof old_onload) | |
onload = old_onload; | |
onload = convert; | |
//window.addEventListener('load', convert); | |
document.head.onload = function() { | |
console.log(typeof onload); | |
if ('function' == typeof onload) { | |
window._onload = onload; | |
window.onload = function(event) { | |
convert(); | |
window._onload(event); | |
} | |
} | |
else | |
window.onload = convert; | |
}*/ | |
//setTimeout(convert, 2000); | |
//document.body.childNodes.item(0).onload = convert; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment