iTunes AppStore QR code

Add QRCode to iTunes AppStore page.

Από την 13/03/2021. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         iTunes AppStore QR code
// @namespace    https://www.iplaysoft.com
// @version      1.01
// @description  Add QRCode to iTunes AppStore page.
// @author       X-Force
// @match        https://apps.apple.com/*
// @grant        none
// @require      https://cdn.staticfile.org/qrious/4.0.2/qrious.min.js
// @require      https://cdn.staticfile.org/jquery/3.4.1/jquery.slim.min.js
// @require     https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012
// @run-at      document-idle
// ==/UserScript==


var $ = window.jQuery;
$(document).ready(function(){

    waitForKeyElements (".we-banner", addQR);

    //Story 下载标题图片
    var url = location.href.split('#')[0];
    var matchStory = url.match(/https?:\/\/apps\.apple\.com\/.+?\/story\/id([0-9]+)/);
    if(matchStory!==null){
        var storyId = matchStory[1];
        //var imgSrcset=document.getElementsByClassName("story__thumbnail")[0].children[0].srcset;
        var imgSrcset=document.getElementsByClassName("we-artwork__source")[0].srcset;
        if(imgSrcset!==null){
            var imgMatch=imgSrcset.match(/(https?:\/\/.+?.(jpg|webp))\s*/);
            if(imgMatch!==null && imgMatch[1]!==null){
                var imgUrl = imgMatch[1];
                console.log(imgUrl);
                var imgUrlVertical = imgUrl.replace(/\/(\d+)x(\d+)(\w+?)\.(jpg|webp)/,"/0x4096h.jpg");
                var imgUrlHorizon = imgUrl.replace(/\/(\d+)x(\d+)(\w+?)\.(jpg|webp)/,"/4096x0w.jpg");
                var myImgButton = document.createElement("div");
                myImgButton.innerHTML = '<a style="margin:20px auto;display:inline-block" target="_blank" href="'+imgUrlHorizon+'">下载封面图片 (横向)</a>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<a style="margin:20px auto;display:inline-block" target="_blank" href="'+imgUrlVertical+'">下载竖向';
                //document.getElementsByClassName("story-card--hero")[0].insertBefore(myImgButton, document.getElementsByClassName("story-card--hero")[0].firstChild);
                //document.getElementsByClassName("story-card")[0].appendChild(myImgButton);
                insertAfter(myImgButton,document.getElementsByClassName("story-card--hero")[0]);
            }
        }
    }
});

function insertAfter(newNode, referenceNode) {
    referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}

function addQR(){
    var url = location.href.split('#')[0];
    //iTunes 页面增加 QR Code
    if(document.title.match("Mac App Store")==null && url.match("\/app\/")){
        var regex = /\/id([0-9]+)/;
        var match = url.match(regex);
        var id = null;
        if(match!==null){
            id = match[1];
        }
        if(id!==null){
            var xurl = "itmss://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id="+id+"&mt=8&at=10laHZ";
            var mydiv = document.createElement("div");
            var html = '<style>#xf_itunes_link{display: inline-block;padding: 8px 22px;background: #228fff;color: #fff;font-size: 16px;border-radius: 6px;}#xf_itunes_link:hover{text-decoration:none}</style>';
            html = html + '<a id="xf_itunes_link" href="'+xurl+'">在 iTunes 中查看</a>';
            html = html + '<canvas id="qrcode" style="position:absolute;right:2px;top:64px;width:200px;height:200px"></canvas>';
            mydiv.innerHTML = html;
            document.getElementsByClassName("product-header")[0].appendChild(mydiv);
            document.getElementsByClassName("product-hero")[0].style.position="relative";
            var qrious = new QRious({
                element: document.getElementById('qrcode'),
                value: url,
                size: 400
            });
        }
    }
}