Skip to content

Instantly share code, notes, and snippets.

@rokdd
Last active April 21, 2023 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rokdd/bf58373a983ca9de4691e8704fb9e839 to your computer and use it in GitHub Desktop.
Save rokdd/bf58373a983ca9de4691e8704fb9e839 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Logviewer
// @namespace rokdd
// @description Scroll down, reload and notify at changes
// @include *.log$
// @include *.log.txt$
// @include *log.html$
// @include *log2.html$
// @version 005
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_log
// @grant GM_notification
// @grant window.focus
// @updateURL https://gist.github.com/rokdd/bf58373a983ca9de4691e8704fb9e839/raw/logviewer.rokdd.user.js
// @downloadURL https://gist.github.com/rokdd/bf58373a983ca9de4691e8704fb9e839/raw/logviewer.rokdd.user.js
// @require https://code.jquery.com/jquery-2.1.4.min.js
// ==/UserScript==
//notification script based on: https://stackoverflow.com/questions/36779883/userscript-notifications-work-on-chrome-but-not-firefox
var duration_default = 30000;
var duration=duration_default;
var duration_after_user=60000
//amount of chars from behind to check for new data
var count_chars=2000;
$("html, body").animate({ scrollTop: $(document).height() });
function injectStylesheet(url) {
$('head').append('<link rel="stylesheet" href="'+url+'" type="text/css" />');
}
function shim_GM_notification () {
if (typeof GM_notification === "function") {
return;
}
window.GM_notification = function (ntcOptions) {
checkPermission ();
function checkPermission () {
if (Notification.permission === "granted") {
fireNotice ();
}
else if (Notification.permission === "denied") {
alert ("User has denied notifications for this page/site!");
return;
}
else {
Notification.requestPermission ( function (permission) {
console.log ("New permission: ", permission);
checkPermission ();
} );
}
}
function fireNotice () {
if ( ! ntcOptions.title) {
console.log ("Title is required for notification");
return;
}
if (ntcOptions.text && ! ntcOptions.body) {
ntcOptions.body = ntcOptions.text;
}
var ntfctn = new Notification (ntcOptions.title, ntcOptions);
if (ntcOptions.onclick) {
ntfctn.onclick = ntcOptions.onclick;
}
if (ntcOptions.timeout) {
setTimeout ( function() {
ntfctn.close ();
}, ntcOptions.timeout);
}
}
}
}
(function() {
'use strict';
$(document).ready(function() {
injectStylesheet("https://cdn.rawgit.com/kamranahmedse/jquery-toast-plugin/bd761d335919369ed5a27d1899e306df81de44b8/dist/jquery.toast.min.css");
var time = new Date().getTime();
$(document.body).bind("mousemove keypress wheel", function(e) {
time = new Date().getTime();
GM_log("Moved something, reset timer and duration")
duration=duration_after_user;
});
function refresh() {
//reload after mousemove 30sek
GM_log((new Date().getTime() - time)+" <> duration: "+duration);
if(new Date().getTime() - time >= duration)
{
window.location.reload(true);
duration=duration_after_user;
}
else
setTimeout(refresh, duration_default+500);
}
shim_GM_notification ();
// store current content in a variable
var eurk = $("html").children(":visible").text();
// compare local storage with current content to make alarm
if (GM_getValue('eurkLoc-'+document.location.href,"")!="" && GM_getValue('eurkLoc-'+document.location.href,"") != eurk.substring(eurk.length-count_chars,count_chars)) {
var url=document.location.href;
var notificationDetails = {
text: 'Content changed. Click to change tab!',
title: ''+url.replace(/^.*\/|\.[^.]*$/g, ''),
timeout: 6000,
onclick: function () { window.focus (); }
};
GM_notification (notificationDetails);
}
else
{
}
//update the last n chars in our settings..
GM_setValue('eurkLoc-'+document.location.href, eurk.substring(eurk.length-count_chars,count_chars));
function resetFunction() {
localStorage.setItem('eurn kLoc', eurk);
};
refresh();
});
//inject jqtoast
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment