diff --git a/Chromium Web Store.crx b/Chromium Web Store.crx index 36dc148..7ab0ba8 100644 Binary files a/Chromium Web Store.crx and b/Chromium Web Store.crx differ diff --git a/src/inject.js b/src/inject.js index 53bad40..4d0ddd8 100644 --- a/src/inject.js +++ b/src/inject.js @@ -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); @@ -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 = ""; diff --git a/src/manifest.json b/src/manifest.json index 6ecfd75..c6bf161 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -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" : [ diff --git a/updates.xml b/updates.xml index 0360213..fcaed32 100644 --- a/updates.xml +++ b/updates.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file