Greasemonkey/VDex_Project_Timezone_Changer.user.js
2014-01-05 19:14:05 +01:00

74 lines
No EOL
2.6 KiB
JavaScript
Executable file

// ==UserScript==
// @name VDex Project Timezone Changer
// @namespace Http://www.enbewe.de/vdex
// @description Lets you change your timezone from the map
// @include http://vdexproject.net/map.php*
// @version 0.3
// ==/UserScript==
var anchor = document.evaluate('//div[@id="footer"]/span',document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var timezoneDiv = document.createElement('div');
timezoneDiv.setAttribute('id','timezoneDiv');
timezoneDiv.innerHTML = 'Zeit: ';
anchor.parentNode.insertBefore(timezoneDiv,anchor);
var timezoneLinkm1 = document.createElement('a');
timezoneLinkm1.setAttribute('class','clickable');
timezoneLinkm1.innerHTML = '(-1)';
timezoneLinkm1.addEventListener("click",function(){changeTimezone(-1)}, true);
timezoneDiv.appendChild(timezoneLinkm1);
var timezoneLink1 = document.createElement('a');
timezoneLink1.setAttribute('class','clickable');
timezoneLink1.innerHTML = '(+1)';
timezoneLink1.addEventListener("click",function(){changeTimezone(1)}, true);
timezoneDiv.appendChild(timezoneLink1);
function changeTimezone(amount) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","/forum/ucp.php?i=165",false);
xmlhttp.send();
var parser = new DOMParser();
var data = parser.parseFromString(xmlhttp.responseText, "text/html");
var params = '';
var snapResults = data.evaluate("//form//input", data, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = snapResults.snapshotLength - 1; i >= 0; i--) {
var elm = snapResults.snapshotItem(i);
if (elm.getAttribute('type') != 'reset' && (elm.getAttribute('type') != 'radio' || elm.getAttribute('checked') == 'checked')) {
params += elm.getAttribute('name')+'='+elm.getAttribute('value')+'&';
}
}
var snapResult = data.evaluate('//form//select[@id="tz"]/option[@selected="selected"]', data, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var timezone = parseInt(snapResult.getAttribute('value'));
params += 'tz='+(timezone+amount);
var url = "/forum/ucp.php?i=prefs&mode=personal";
var http = new XMLHttpRequest();
http.open("POST", url, false);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(params);
if (http.responseText.search(/preferences\shave\sbeen\supdated/)) {
window.location.reload();
} else {
alert('Fail:\n'+http.responseText);
}
}