-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: make script working on Chromium #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
// @contributionAmount feel free to fork and contribute | ||
// @include https://chrome.google.com/webstore/detail/*/* | ||
// @noframes 1 | ||
// @run-at window-load | ||
// @optimize 1 | ||
// ==/UserScript== | ||
|
||
|
@@ -40,14 +39,15 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <http://unlicense.org/>*/ | ||
"use strict"; | ||
|
||
const downloadUriTemplate="https://clients2.google.com/service/update2/crx?response=redirect&prodversion=38.0&x=id%3D$ID$%26installsource%3Dondemand%26uc "; | ||
const downloadUriTemplate="https://clients2.google.com/service/update2/crx?response=redirect&prodversion=$VER$&x=id%3D$ID$%26installsource%3Dondemand%26uc "; | ||
function getBrowserVersion() { | ||
return window.navigator.userAgent.match(/Chrome\/([0-9.]+)/)[1]; | ||
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 will be broken in the browsers other than Chrome. The script is targeted for Firefox users, because chrome users already have the mean to download crxes. 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. Hardcoded version number was kinda strange, but now I understand. Well, fallback could be added for the case if no match was found. |
||
} | ||
function parseAddonUri(path){ | ||
let a=path.split("/"); | ||
return {download:downloadUriTemplate.replace("$ID$",a[a.length-1]),id:a[a.length-2]}; | ||
} | ||
function getButton(){ | ||
return document.body.querySelector("div[role=button]"); | ||
return {download:downloadUriTemplate.replace("$ID$",a[a.length-1]).replace("$VER$",getBrowserVersion()),id:a[a.length-2]}; | ||
} | ||
function getFilename(){ | ||
return getAddonName(); | ||
|
@@ -58,12 +58,12 @@ function getAddonName(){ | |
function replaceButton(){ | ||
let parsed=parseAddonUri(window.location.pathname); | ||
let a=document.createElement("A"); | ||
a.download=parsed.id+".crx"; | ||
//a.download=parsed.id+".crx"; | ||
a.href=parsed.download; | ||
a.textContent="Download .CRX"; | ||
|
||
let btn=getButton(); | ||
a.className=btn.className; | ||
btn.parentNode.replaceChild(a,btn); | ||
a.style = 'display: block; margin-bottom: 1em;'; | ||
|
||
let descEl = document.querySelector('div[itemprop="description"]'); | ||
descEl.insertBefore(a, descEl.firstChild); | ||
} | ||
setTimeout(replaceButton,3000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that this will work in chrome without wrapping into a closure? As I know, it won't. Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously, I've tested it before submitting.