SHIFT切换选项卡自动跳转指定网页(摸鱼模板)

长按 Shif键切换网页

// ==UserScript==
// @name         SHIFT切换选项卡自动跳转指定网页(摸鱼模板)
// @namespace    http://www.
// @version      0.1.1
// @license MIT
// @description  长按 Shif键切换网页
// @author       Your name
// @match        *://*/*
// @grant        none
// ==/UserScript==

var longpress = false;
var presstimer = null;
var pageurl = window.location.href;

document.addEventListener('keydown', function(e) {
  if (e.keyCode == 16) { // 判断是否按下 Shift 键
    longpress = true;
    if (!presstimer){// && e.keyCode == 65) { // 判断是否按下 A 键
      presstimer = setTimeout(function(){
        var tabs = [];
        var selectedTabIndex = -1;
         // alert('')
         window.location.href="https://github.com/search?q=owner%3Akant2002++_SuppressWinFormsTrimError&type=code"
        //  https://github.com/search?q=owner%3Akant2002++_SuppressWinFormsTrimError&type=code
      /*  windows.getCurrent({populate: true}, function(window){
          window.tabs.forEach(function(tab, index){
            if (tab.url !== '' && tab.url !== 'chrome://newtab/' && tab.url !== 'about:newtab' && tab.url.indexOf(pageurl) < 0) {
              tabs.push(tab);
              if (tab.active) selectedTabIndex = index;
            }
          });

          if (tabs.length >= 1) {
            var nextTabIndex = (selectedTabIndex+1) % tabs.length;
            window.location.replace(tabs[nextTabIndex].url);
          }
        });*/

        presstimer = null;
      }, 1500);
    }
  }
});

document.addEventListener('keyup', function(e) {
  if (e.keyCode == 16 ){//&& e.keyCode == 65) { // 判断是否同时松开 Shift+A 键
    if (presstimer !== null) {
      clearTimeout(presstimer);
      presstimer = null;
    }
    longpress = false;
  }
});