Skip to content

Instantly share code, notes, and snippets.

@luizbafilho
Last active September 19, 2022 12:07
Show Gist options
  • Save luizbafilho/68ad756df856471088a5e35e0ef00831 to your computer and use it in GitHub Desktop.
Save luizbafilho/68ad756df856471088a5e35e0ef00831 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Imersion Timer
// @namespace https://gist.github.com/luizbafilho
// @version 0.1
// @description try to take over the world!
// @author luizbafilho
// @match https://jpdb.io/review*
// @match https://bunpro.jp/*
// @match https://zoro.to/*
// @match https://htpc.luizbafilho.dev/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require https://cdn.jsdelivr.net/gh/saleemkce/timeonsite@1.2.0/timeonsitetracker.min.js
// @grant GM_xmlhttpRequest
// @connect jp-timer.cloud.luizbafilho.dev
// ==/UserScript==
function getCategory() {
switch (window.location.host) {
case 'bunpro.jp':
return "grammar";
case 'jpdb.io':
return "srs";
case 'zoro.to':
return "listening";
case 'htpc.luizbafilho.dev':
return "reading";
default:
return "";
}
}
(function() {
'use strict';
var username = localStorage.getItem('jp_tracker_username');
var password = localStorage.getItem('jp_tracker_password');
var endpointUrl = localStorage.getItem('jp_tracker_url');
username = "luiz";
password = "qwe123@"
endpointUrl = "https://jp-timer.cloud.luizbafilho.dev/entries.json"
setInterval(function() {
if(document.hidden) {
return
}
var date = new Date()
date.setHours(date.getHours() - 3);
var d = {
"day": date.toJSON().slice(0,10).replace(/-/g,'/'),
"duration": 1,
"category": getCategory()
}
//console.log("Sending...", d)
GM_xmlhttpRequest ( {
method: 'POST',
url: endpointUrl,
data: JSON.stringify(d),
//user: username,
//password: password,
headers: {
"Content-Type": "application/json",
"Authorization": "Basic " + btoa(username + ":" + password)
},
onload: function (responseDetails) {
if (responseDetails.status != 201) {
console.log ( "GM_xmlhttpRequest() response is:\n", responseDetails.responseText.substring (0, 80) + '...');
}
},
onerror: function (responseDetails) {
// DO ALL RESPONSE PROCESSING HERE...
console.log (
"GM_xmlhttpRequest() response is:\n",
responseDetails.responseText.substring (0, 80) + '...'
);
}
});
}, 1000);
// Your code here...
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment