Skip to content

Instantly share code, notes, and snippets.

@cyroxx
Created March 12, 2012 14:24
Show Gist options
  • Save cyroxx/2022237 to your computer and use it in GitHub Desktop.
Save cyroxx/2022237 to your computer and use it in GitHub Desktop.
Userscript: Show a QR code in order to easily open up the same page on your mobile device.
// ==UserScript==
// @name Google Play QR Code
// @namespace Google Play
// @description Show a QR code in order to easily open up the same page on your mobile device.
// @include https://play.google.com/store/apps/details?id=*
// ==/UserScript==
(function() {
findxpath = function(root, xpath) {
return document.evaluate(xpath, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
}
findxpath_singleNode = function(root, xpath) {
return document.evaluate(xpath, root, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
};
let path = findxpath_singleNode(document, "//link[@rel='canonical']").href;
let blocks = findxpath(document, "//td[contains(@class, 'doc-banner-title-container')]");
var newImg = document.createElement("img");
newImg.src = "http://chart.googleapis.com/chart?chs=100x100&cht=qr&chld=L|1&chl=" + encodeURIComponent(path);
newImg.alt = "QR code link to this page";
for (i = 0; block = blocks.snapshotItem(i); i++) {
// insert QR code as first child
block.insertBefore(newImg, block.firstChild);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment