Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems inserting a text node before an existing element using Greasemonkey
    text
    copied!<p>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.</p> <p>A target page, that you can access without logging in, is <a href="http://www.thepikaclub.co.uk/adopt/trainercard.php?trainer=10220" rel="nofollow">Here</a></p> <p>The id of the div I want to insert my node before appears to be <code>clock-wrapper</code></p> <p>Code I've tried: (inserted between the alert and console.log, in the "original script", below)</p> <pre><code>var textNode = document.createElement('b'); var clock=document.getElementById('clock-wrapper'); textNode.appendChild ('&lt;b&gt;' + serverTime + '&lt;/b&gt;'); clock.parentNode.insertBefore(textNode, clock); </code></pre> <p>and</p> <pre><code>var textNode = document.createElement('b'); var getRef = document.getElementById("clock-wrapper"); var parentDiv = getRef.parentNode; parentDiv.insertBefore(textNode, getRef); </code></pre> <p><br/></p> <p>Here is the <em>original script</em>:</p> <pre><code>// ==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 &amp;&amp; RespDate.length &gt; 1) { serverTime = RespDate[1]; } alert ("Server Time: " + serverTime); console.log ("Server Time: ", serverTime); } } ); </code></pre> <p><br/> 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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload