Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name New tab from Urlbar
- // @description URLバーから新しいタブで開く
- // @namespace 5ch
- // @include main
- // @license MIT
- // @version 0.0.1
- // ==/UserScript==
- (() => {
- "use strict";
- const openInTabService = {
- _oldHandleCommand: null,
- isNewTab: function(url) {
- if (!url)
- return false;
- if (/^moz-action:visiturl,/.test(url)) {
- const json = JSON.parse(url.substring(20));
- url = decodeURIComponent(json.url);
- }
- let isBlank = false;
- let tab = gBrowser.mCurrentTab;
- if (!(tab.hasAttribute("pinned") || tab.hasAttribute("busy") || tab.hasAttribute("pending"))) {
- try {
- if (/^\s*about:(blank|newtab|home)/i.test(gBrowser.mCurrentBrowser.currentURI.spec))
- isBlank = true;
- } catch (e) {
- isBlank = true;
- }
- }
- return (isBlank || /^\s*(javascript|mailto):/i.test(url))? false: true;
- },
- newHandleCommand: function(event, where, param) {
- if (!where) {
- if (openInTabService.isNewTab(gURLBar.value))
- where = "tab";
- }
- openInTabService._oldHandleCommand.call(gURLBar, event, where, param);
- },
- start: function() {
- if (this._oldHandleCommand == null) {
- this._oldHandleCommand = gURLBar.handleCommand;
- gURLBar.handleCommand = this.newHandleCommand;
- }
- },
- };
- openInTabService.start();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement