html Bookmarklet可在不久的将来某个时刻自动刷新任何页面。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Bookmarklet可在不久的将来某个时刻自动刷新任何页面。相关的知识,希望对你有一定的参考价值。

// prevent IE errors when using console
if (typeof console === "undefined") {
		window.console = {
			log: function () {}
		};
}

var inFuture = new Date(new Date().getTime() + 10*60000);
var inHour = inFuture.getHours();
var inMin = (inFuture.getMinutes()<10?'0':'') + inFuture.getMinutes();


var inputdata = prompt("What time should this page refresh?\nThis is a 24 clock. 0:00 = Midnight, 13:00 = 1pm\nThe default is for 10 minutes from now: "+inHour+":"+inMin,inHour+":"+inMin);

function refreshAt(hours, minutes, seconds) {
    var now = new Date();
    var then = new Date();

    if(now.getHours() > hours ||
       (now.getHours() == hours && now.getMinutes() > minutes) ||
        now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
        then.setDate(now.getDate() + 1);
    }
    then.setHours(hours);
    then.setMinutes(minutes);
    then.setSeconds(seconds);

    var timeout = (then.getTime() - now.getTime());
    setTimeout(function() { window.location.reload(true); }, timeout);

    var reportedHour = hours;
    var ampm = 'am';
    if (reportedHour > 12) {
    	reportedHour -= 12;
    	ampm = 'pm';
    }

    console.log('This page will refresh at ' + reportedHour + ":" + (minutes<10?'0':'')+minutes + ampm);
}

if (null !== inputdata) {

var newtime = inputdata.split(':');
console.log(newtime);

refreshAt(parseInt(newtime[0]),parseInt(newtime[1]),0);
} else {
	console.log("No value submitted.")
}
<!DOCTYPE html>
<html>
<head>
	<title>Page Refresher</title>
</head>
<body>
	<h1>Page Refresher</h1>
	<p>Drag the link below to your toolbar to install the "page refresher" bookmarklet. Press the bookmarklet and you will be prompted for when you'd like the page you're on to be refreshed in your browser.</p>
	<a href="javascript: (function () {  var jsCode = document.createElement('script');  jsCode.setAttribute('src', 'https://gist.githubusercontent.com/johnfmorton/9238562/raw/b2a65b62c17569d3d275b9f2a755d14658e8d036/pagerefresher.js'); document.body.appendChild(jsCode); }());">Refresher</a>

</body>
</html>

以上是关于html Bookmarklet可在不久的将来某个时刻自动刷新任何页面。的主要内容,如果未能解决你的问题,请参考以下文章

Django 是不是有计划在不久的将来放弃对 Python 2 的支持? [关闭]

html PrismJS Bookmarklet示例

HTML Ventriloquist Bookmarklet

5G时代的到来,会给生活带来什么改变?

javascript Bookmarklet:清除YouTube中的视频

JavaScript 带有jquery的bookmarklet