Skip to content

Instantly share code, notes, and snippets.

@XP1
Created May 26, 2012 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XP1/2794864 to your computer and use it in GitHub Desktop.
Save XP1/2794864 to your computer and use it in GitHub Desktop.
Enhance Chrome Web Store: Replaces the "Available on Chrome" button, shown to other browsers, with the application download button.
// ==UserScript==
// @name Enhance Chrome Web Store
// @version 1.03
// @description Replaces the "Available on Chrome" button, shown to other browsers, with the application download button.
// @namespace https://gist.github.com/2794864/
// @copyright 2012
// @author XP1
// @homepage https://github.com/XP1/
// @license Apache License, Version 2.0; http://www.apache.org/licenses/LICENSE-2.0
// @include http*://chrome.google.*/webstore/detail/*
// @include http*://*.chrome.google.*/webstore/detail/*
// ==/UserScript==
/*
* Copyright 2012 XP1
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*jslint browser: true, vars: true, maxerr: 50, indent: 4 */
(function (console, window, ANY_TYPE) {
"use strict";
var userScript = {
name: "Enhance Chrome Web Store"
};
var handleException = function handleException(theFunction) {
try {
theFunction();
} catch (exception) {
console.error("[" + userScript.name + "]: Exception: " + exception + "\n\nStack:\n" + exception.stack + "\n\nStacktrace:\n" + exception.stacktrace);
}
};
function getApplicationId() {
var location = window.location;
var names = location.pathname.split("/");
var idRegex = /[A-Za-z0-9]{32}/g;
var i = null;
for (i = names.length; i >= 0; i -= 1) {
var id = names[i];
if (idRegex.test(id)) {
return id;
}
}
throw new Error("Cannot find application ID.");
}
function showDownload() {
var document = window.document;
var location = window.location;
var button = document.evaluate("//div[@role=\"button\"][.=\"Available on Chrome\"]", document, null, ANY_TYPE, null).iterateNext();
document.evaluate("//[text()=\"Available on Chrome\"]", button, null, ANY_TYPE, null).iterateNext().setAttribute("id", "buttonLabel");
var parent = button.parentNode;
var downloadUri = "https://clients2.google.com/service/update2/crx?response=redirect&x=id%3D" + getApplicationId() + "%26uc%26lang%3Den";
var downloadButton = button.cloneNode(true);
downloadButton.querySelector("#buttonLabel").textContent = "Download";
downloadButton.addEventListener("click", function downloadButtonClick() {
location.assign(downloadUri);
}, false);
parent.insertBefore(downloadButton, button);
parent.removeChild(button);
}
function initialize() {
var functions = [showDownload];
var i = null;
var length = functions.length;
for (i = 0; i < length; i += 1) {
handleException(functions[i]);
}
}
window.addEventListener("DOMFrameContentLoaded", initialize, false);
}(this.console, this, this.XPathResult.ANY_TYPE));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment