Advertisement
Guest User

NewTabFromUrlbar.uc.js

a guest
Nov 16th, 2017
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           New tab from Urlbar
  3. // @description    URLバーから新しいタブで開く
  4. // @namespace      5ch
  5. // @include        main
  6. // @license        MIT
  7. // @version        0.0.1
  8. // ==/UserScript==
  9. (() => {
  10. "use strict";
  11. const openInTabService = {
  12.     _oldHandleCommand: null,
  13.  
  14.     isNewTab: function(url) {
  15.         if (!url)
  16.             return false;
  17.  
  18.         if (/^moz-action:visiturl,/.test(url)) {
  19.             const json = JSON.parse(url.substring(20));
  20.             url = decodeURIComponent(json.url);
  21.         }
  22.  
  23.         let isBlank = false;
  24.         let tab = gBrowser.mCurrentTab;
  25.         if (!(tab.hasAttribute("pinned") || tab.hasAttribute("busy") || tab.hasAttribute("pending"))) {
  26.             try {
  27.                 if (/^\s*about:(blank|newtab|home)/i.test(gBrowser.mCurrentBrowser.currentURI.spec))
  28.                     isBlank = true;
  29.             } catch (e) {
  30.                 isBlank = true;
  31.             }
  32.         }
  33.  
  34.         return (isBlank || /^\s*(javascript|mailto):/i.test(url))? false: true;
  35.     },
  36.  
  37.     newHandleCommand: function(event, where, param) {
  38.         if (!where) {
  39.             if (openInTabService.isNewTab(gURLBar.value))
  40.                 where = "tab";
  41.         }
  42.         openInTabService._oldHandleCommand.call(gURLBar, event, where, param);
  43.     },
  44.  
  45.     start: function() {
  46.         if (this._oldHandleCommand == null) {
  47.             this._oldHandleCommand = gURLBar.handleCommand;
  48.             gURLBar.handleCommand = this.newHandleCommand;
  49.         }
  50.     },
  51. };
  52.  
  53. openInTabService.start();
  54. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement