-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
61 lines (45 loc) · 1.76 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// ==UserScript==
// @name Fiverr Auto Refresh
// @namespace http://tampermonkey.net/
// @version V1.0
// @description this script can refresh web page with random timing, its usually used for remaing online on different platforms like Fiverr, UpWork
// @author Talha Rafique
// @contact [email protected]
// @match
// @exampleLink
// ==/UserScript==
var minMinutes = 4;
var maxMinutes = 8;
var startTime ;
var totalTime;
var currentTime;
var remainingTime;
function random(min, max) {
return min + Math.random() * (max - min);
}
totalTime = Math.floor(random(minMinutes, maxMinutes) *60*1000);
startTime = new Date().getTime() + totalTime;
//Page refresh APi
setTimeout (function(){location.reload();},totalTime );
//convert time into minute and seconds
function millisToMinutesAndSeconds(millis) {
var minutes = Math.floor(millis / 60000);
var seconds = ((millis % 60000) / 1000).toFixed(0);
return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
}
//make div on page where display remaining time.
var div = document.createElement("div");
div.setAttribute("id", "timerId");
div.setAttribute("class", "timerClass");
// style, set position and style to display
var style = document.createElement("STYLE");
var value = document.createTextNode("#timerId {position: fixed; top: 85px; left: 0px; color: red; font-weight: bold;} .timerClass { width: 200px; height: 30px; padding-left: 20px;}");
style.appendChild(value);
document.head.appendChild(style);
//calculate time and refresh time
window.setInterval(function(){
currentTime = new Date().getTime();
remainingTime =startTime- currentTime;
div.innerHTML = "Auto Refresh In = " + millisToMinutesAndSeconds(remainingTime) + " ";
document.body.append(div);
}, 1000);