Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions crxDownloader.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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==

Expand Down Expand Up @@ -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";
Copy link
Member

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.

Copy link
Author

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.


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];
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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();
Expand All @@ -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);