Skip to content

Commit

Permalink
Correctly handles url fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverDecaf committed Aug 18, 2019
1 parent e2a38c3 commit 2c6a59f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
Binary file modified Chromium Web Store.crx
Binary file not shown.
36 changes: 24 additions & 12 deletions src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,54 @@
var bodyObserver = new MutationObserver(function (mutations) {

function getExtensionId(url) {
url = url.split('#')[0].split('?')[0];
var pathfrags = url.split('/');
return pathfrags[pathfrags.length-1];
};
function buildExtensionUrl(extensionId) {
var chromeVersion = /Chrome\/([0-9.]+)/.exec(navigator.userAgent)[1];
return 'https://clients2.google.com/service/update2/crx?response=redirect&acceptformat=crx2,crx3&prodversion='+chromeVersion+'&x=id%3D'+extensionId+'%26installsource%3Dondemand%26uc'
return 'https://clients2.google.com/service/update2/crx?response=redirect&acceptformat=crx2,crx3&prodversion='+chromeVersion+'&x=id%3D'+extensionId+'%26installsource%3Dondemand%26uc';
};
mutations.forEach(function (mutation) {
if (mutation.attributeName == 'class' && mutation.target.tagName == 'DIV' && (mutation.target.className == 'a-eb-mb-x' || mutation.target.hasAttribute('webstore-source'))) {
var xpathResult = document.evaluate( '//div[div[@aria-label="Available on Chrome"] or (@class="h-e-f-Ra-c e-f-oh-Md-zb-k" and not(node())) ]', document, null, XPathResult.ANY_TYPE, null);

var results = [];
while (result = xpathResult.iterateNext())
results.push(result);

for (var i=0; i < results.length; i++) {

button_div = document.createElement( 'div' );
var button_div = document.createElement( 'div' );
button_div.setAttribute('role','button');
button_div.setAttribute('class','dd-Va g-c-wb g-eg-ua-Uc-c-za g-c-Oc-td-jb-oa g-c');
button_div.setAttribute('aria-label','Add to Chromium');
button_div.setAttribute('tabindex','0');
button_div.setAttribute('style','user-select: none;');

hf = document.createElement( 'div' );
var dlurl = '';
if (parentpanel = results[i].closest('a')) {
dlurl = buildExtensionUrl(getExtensionId(parentpanel.href));
parentpanel.setAttribute('ext_dl_url',dlurl);
parentpanel.addEventListener("click",function(){
this.setAttribute('id','ext_dl_url');
});
}
else if (clickedon = document.getElementById('ext_dl_url')) {
clickedon.removeAttribute('id');
dlurl = clickedon.getAttribute('ext_dl_url');
}
else {
dlurl = buildExtensionUrl(getExtensionId(document.head.querySelector('meta[property="og:url"]').getAttribute('content')));
}
button_div.setAttribute('ext_dl_url',dlurl);

var hf = document.createElement( 'div' );
hf.setAttribute('class','g-c-Hf');
button_div.appendChild(hf);

x = document.createElement( 'div' );
var x = document.createElement( 'div' );
x.setAttribute('class','g-c-x');
hf.appendChild(x);

R = document.createElement( 'div' );
var R = document.createElement( 'div' );
R.setAttribute('class','g-c-R webstore-test-button-label');
R.innerHTML = 'Add to Chromium';
x.appendChild(R);
Expand All @@ -46,10 +61,7 @@ var bodyObserver = new MutationObserver(function (mutations) {
this.classList.remove('g-c-l');
});
button_div.addEventListener("click",function(){
if (this.parentElement.className == 'h-e-f-Ra-c e-f-oh-Md-zb-k')
window.open(buildExtensionUrl(getExtensionId(document.location.href)))
else
window.open(buildExtensionUrl(getExtensionId(this.closest('a').href)));
window.open(this.getAttribute('ext_dl_url'));
});

results[i].innerHTML = "";
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "NeverDecaf",
"manifest_version": 2,
"name": "Chromium Web Store",
"version": "0.2",
"version": "0.3",
"description": "Allow installing extensions from chrome web store on chromium based browsers.",
"background": { "scripts": ["background.js"] },
"permissions" : [
Expand Down
2 changes: 1 addition & 1 deletion updates.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='ocaahdebbfolfmndjeplogmgcagdmblk'>
<updatecheck codebase='https://github.com/NeverDecaf/chromium-web-store/releases/latest/download/Chromium.Web.Store.crx' version='0.2' />
<updatecheck codebase='https://github.com/NeverDecaf/chromium-web-store/releases/latest/download/Chromium.Web.Store.crx' version='0.3' />
</app>
</gupdate>

0 comments on commit 2c6a59f

Please sign in to comment.