my zhihu

知乎计时插件

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         my zhihu
// @namespace    xay5421
// @version      0.1
// @author       xay5421
// @description  知乎计时插件
// @match        https://www.zhihu.com/*
// @require       https://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==

var $=window.$;
$(function(){
	var t=localStorage.endTime;
	var x;
	if(t==undefined||t<=+new Date()){
		if(t!=undefined)alert("时间到了");
		while(1){
			x=prompt("这一次你想水多少分钟的知乎?");
			if(x==undefined){
				$("body").find("*").remove();
				alert("看来这次你不想水知乎");
				delete localStorage.endTime;
				return;
			}
			x=parseFloat(x);
			if(x.toString()=="NaN")alert("请输入一个数字");else
			if(x<0)alert("这个数字要大于 0");else
			if(x>10)alert("时间太长了,不能超过十分钟,好好写题,不要水来水去");else break;
		}
		x=x*60*1000;
		localStorage.endTime=+new Date()+x;
	}
	if(t>+new Date()){
		setTimeout(function(){$("body").find("*").remove();alert("时间到了");delete localStorage.endTime;},t-(+new Date()));
	}else{
		setTimeout(function(){$("body").find("*").remove();alert("时间到了");delete localStorage.endTime;},x);
	}
});