Social Limit

Prevents being on social media too long

当前为 2019-03-09 提交的版本,查看 最新版本

// ==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.20190309195842
// ==/UserScript==

const LIMIT = 1000*60;


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);

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

if(socialmedia.has(location.hostname)) {
 console.log('Is social media');
 var alerttimeout = null;
 onfocus();
 $(window).focus(onfocus);
 $(window).blur(()=>{
  if(alerttimeout) {
   clearTimeout(alerttimeout);
  }
  GM_setValue('latest',Date.now());
 });
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址