Social Limit

Prevents being on social media too long

安裝腳本?
作者推薦腳本

您可能也會喜歡 Sugg

安裝腳本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name Social Limit
// @namespace Fusir Projects
// @description Prevents being on social media too long
// @match *://*/*
// @grant GM_setValue
// @grant GM_getValue
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @version 0.0.1.20190309201947
// ==/UserScript==

const LIMIT = 1000*60*15;
const COOLDOWN = 1000*60*15;


var socialmedia = ['voat.co','phuks.co','notabug.io','hooktube.com','invidio.us',
'reddit.com','facebook.com','twitter.com','gab.io','poal.co','instagram.com',
'youtube.com'];
socialmedia = new Set(socialmedia);

var isalert=false; //Used to not count visits while being alerted so going back prematurely doesn't reset the whole cool down.

function onfocus() {
var earliest = GM_getValue('earliest') || null;
  var latest = GM_getValue('latest') || 0;
  if(Date.now()-latest>COOLDOWN) {
   console.log('Set new earliest');
   earliest=Date.now();
  }
  latest=Date.now();
  if(earliest && Date.now()-earliest>LIMIT) {
   isalert=true;
   alert('Close all social media');
  }
  else {
   alerttimeout = setTimeout(()=>{
    isalert=true;
    alert('Close all social media');
   },LIMIT+earliest-Date.now());
   isalert = false;
   GM_setValue('latest',latest);
  }
  GM_setValue('earliest',earliest);
}

if(socialmedia.has(location.hostname)) {
 console.log('Is social media');
 var alerttimeout = null;
 onfocus();
 $(window).focus(onfocus);
 $(window).blur(()=>{
  if(alerttimeout) {
   clearTimeout(alerttimeout);
  }
  if(!isalert) {
   //If we are being alerted don't count it as a view.
   GM_setValue('latest',Date.now());
  }
 });
}