GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Added @include with url of active tab by Cerberus-tm · Pull Request #3231 · greasemonkey/greasemonkey Conversation
Contributor
Gets the url of the active tab and adds @include with the url to the template for new scripts. I am new to editing/committing stuff on Github and webextensions, so I hope this works. Better check it just in case.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsGets the url of the active tab and adds @include with the url to the template for new scripts. I am new to editing/committing stuff on Github and webextensions, so I hope this works. Better check it just in case.
arantius
reviewed
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd write this simply
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I wanted to do that, but I was slightly afraid I might have misunderstood something about what happens in JS if you try to access an item in an array that doesn't exist, was afraid of some blocking error so played it extra safe. But then let's do
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's probably more common to write a script for a whole site than for just one particular URL?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is true, I thought about that as well; but it is not so rare to want more than just the domain, and deleting the end is much easier for the user than adding it back, was my thought.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When compatible I'd suggest
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK I wasn't sure how
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already in a backtick string, so just
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
| let r = Math.floor(Math.random() * 900000 + 100000); | ||
| let name = _('unnamed_script_RAND', r); | ||
| let scriptSource = `// ==UserScript== | ||
| let match_url = '*'; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Oh, phooey.
@match * is not valid. For match it's <all_urls>. (Match syntax is more complicated and I didn't remember it myself.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I should have checked that. Will switch to <all_urls>.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| let match_url = '*'; | ||
| let active_tabs = chrome.tabs | ||
| .query({'active': true, 'currentWindow': true}); | ||
| if (active_tabs[0]?.url) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Accidentally said this in the commit, but a much shorter/more idiomatic form would be:
let match_url = active_tabs[0]?.url || '<all_urls>';
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I considered it but wasn't 1000% certain how that behaved so I was probably being too safe. Will use that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for contributing! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for helping me! I edited the file in my fork of the repository each time, then pressed the buttons that appeared, to push it to the master branch. I hope the result was the proper way / wasn't inconvenient for others; I don't know how Github works. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
`.tabs.query()` was returning undefined. Be sure to try/catch as docs say `.getCurrent()` might throw. Refs greasemonkey#3231
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.