I have a script that gets the current server time and it works great. Problem is, I'd like to insert the server time right before the clock on the page (that shows local time even though activities on the site tell you that you can do it again at a specific server time). For some reason I can't figure out how to stick the darn thing where I want it.
A target page, that you can access without logging in, is Here
The id of the div I want to insert my node before appears to be clock-wrapper
Code I've tried: (inserted between the alert and console.log, in the "original script", below)
var textNode = document.createElement('b');
var clock=document.getElementById('clock-wrapper');
textNode.appendChild ('<b>' + serverTime + '</b>');
clock.parentNode.insertBefore(textNode, clock);
and
var textNode = document.createElement('b');
var getRef = document.getElementById("clock-wrapper");
var parentDiv = getRef.parentNode;
parentDiv.insertBefore(textNode, getRef);
Here is the original script:
// ==UserScript==
// @name test server time
// @namespace http://trueidiocy.us
// @include https://www.google.com
// @include http://stackoverflow.com
// @include http://www.thepikaclub.co.uk*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
GM_xmlhttpRequest ( {
url: location.href,
method: "HEAD",
onload: function (rsp) {
var serverTime = "Server date not reported!";
var RespDate = rsp.responseHeaders.match (/\bDate:\s+ (.+?) (?:\n|\r)/i);
if (RespDate && RespDate.length > 1) {
serverTime = RespDate[1];
}
alert ("Server Time: " + serverTime);
console.log ("Server Time: ", serverTime);
}
} );
What am I missing here? Do I just need to find a better reference source than I was using for future scripts? Also, how difficult would it be to make the script run again to update the time every minute or so?