Created
September 28, 2021 15:16
-
-
Save bburky/4519d913588c1e268ed82df42e65a398 to your computer and use it in GitHub Desktop.
Open Google Apps scripts in new tab on middle click greasemonkey script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Open Google Apps scripts in new tab on middle click | |
// @namespace https://bburky.com/ | |
// @match https://script.google.com/* | |
// @grant none | |
// @version 1.0 | |
// @author - | |
// @description Note: broken on non-apps script links (docs scripts, etc). Only works with middle click (not cmd-click). | |
// @inject-into content | |
// ==/UserScript== | |
(async function() { | |
'use strict'; | |
const { default: monitoring} = await import('https://cdn.jsdelivr.net/npm/monitoring/dist/monitoring-latest.min.mjs'); | |
const monitor = monitoring(document.body); | |
monitor.added("div[aria-label='Project list']", projectList => { | |
Array.from(projectList.children).forEach(div => { | |
const scriptId = div.dataset.scriptId; | |
const urlPrefixMatch = /^\/(u\/\d+\/)/.exec(document.location.pathname); | |
const urlPrefix = urlPrefixMatch ? urlPrefixMatch[1] : ""; | |
const url = `/${urlPrefix}home/projects/${scriptId}/`; | |
console.log(url); | |
div.addEventListener('auxclick', function(e) { | |
e.preventDefault(); | |
window.open(url, '_blank').focus(); | |
}); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment