Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first code snippet, in the question, is invalid (bad <code>appendChild</code> call), but the second code snippet would work -- except that the <code>&lt;b&gt;</code> tag was added with empty contents.</p> <p>Anyway, since your base script is (wisely) loading jQuery, <em>use it</em>. jQuery's <code>.before()</code> works great here. The code would be:</p> <pre><code>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]; } $("#clock-wrapper").before ('&lt;b&gt;' + serverTime + '&lt;/b&gt;'); } } ); </code></pre> <hr> <p>If you want to re-fetch the server time every minute, or so, use javascript's <code>setInterval()</code>. Except that you need to avoid creating more than one <code>&lt;b&gt;</code> tag, so the code needs an additional check. It becomes:</p> <pre><code>getServerTime (); //-- Initial call //-- Recheck every minute var clkRefreshTimer = setInterval (getServerTime, 60 * 1000); // 60 seconds function getServerTime () { 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]; } //-- Does our display node already exist? var ourTimeDisp = $("#gmTimeDisplay"); if (ourTimeDisp.length) { ourTimeDisp.text (serverTime); } else { $("#clock-wrapper").before ( '&lt;b id="gmTimeDisplay"&gt;' + serverTime + '&lt;/b&gt;' ); } } } ); } </code></pre> <hr> <p><strong>However</strong>, you might be smart to look up how to add a JS clock to the page and only call <code>GM_xmlhttpRequest</code> <em>once</em> just to initialize your new clock. Then your clock JS would update it as often as you liked without aggravating the server. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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