Load .gsheet link from local file

Discover Google Docs link in .gsheet file and navigate to it. 2020-03-02.

  1. // ==UserScript==
  2. // @name Load .gsheet link from local file
  3. // @version 0.2
  4. // @description Discover Google Docs link in .gsheet file and navigate to it. 2020-03-02.
  5. // @author Jefferson "jscher2000" Scher
  6. // @namespace JeffersonScher
  7. // @copyright Copyright 2020 Jefferson Scher
  8. // @license BSD-3-Clause
  9. // @match file:///*/*
  10. // @grant GM_registerMenuCommand
  11. // @run-at document-idle
  12. // ==/UserScript==
  13.  
  14. function loadSheet(){
  15. // Parse document text as JSON
  16. var oSheetInfo = JSON.parse(document.body.textContent);
  17. // Replace current page with linked page
  18. if (oSheetInfo.url.indexOf('https://docs.google.com/') === 0){
  19. // Go directly to HTTPS link
  20. location.replace(oSheetInfo.url);
  21. } else if (oSheetInfo.url.indexOf('http://docs.google.com/') === 0){
  22. // Upgrade HTTP link
  23. location.replace(oSheetInfo.url.replace('http://', 'https://'));
  24. } else {
  25. // Ask user about WTF link
  26. if (confirm('Navigate to "' + oSheetInfo.url + '"?')){
  27. location.replace(oSheetInfo.url);
  28. }
  29. }
  30. }
  31.  
  32. // Detect documents whose paths end with .gsheet and run loadSheet(), add menu item
  33. if (location.pathname.indexOf('.gsheet') > -1 && location.pathname.slice(-7) == '.gsheet'){
  34. window.setTimeout(loadSheet, 50);
  35. // This should work in Violentmonkey and Tampermonkey, but unfortunately not Greasemonkey.
  36. try {
  37. GM_registerMenuCommand("Navigate now", loadSheet);
  38. } catch (err) {
  39. console.log('Error adding Load .gsheet from local file menu items: ' + err.message);
  40. }
  41. }

QingJ © 2025

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