Stig's Art Grabr

Grabbing big high resolution album cover-art from various sites

目前為 2016-06-22 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Stig's Art Grabr
// @namespace   dk.rockland.userscript.misc.artgrab
// @description Grabbing big high resolution album cover-art from various sites
// @version     2016.06.22.1
// @match       *://*.allmusic.com/*
// @match       *://*.bandcamp.com/*
// @match       *://*.itunes.apple.com/*
// @match       *://*.musicdiner.com/*
// @match       *://*.fnd.io/*
// @match       *://labs.stephenou.com/itunes/*
// @match       *://*.last.fm/*
// @match       *://*.lastfm.de/*
// @match       *://*.lastfm.es/*
// @match       *://*.lastfm.fr/*
// @match       *://*.lastfm.it/*
// @match       *://*.lastfm.ja/*
// @match       *://*.lastfm.pl/*
// @match       *://*.lastfm.pt/*
// @match       *://*.lastfm.ru/*
// @match       *://*.lastfm.sv/*
// @match       *://*.lastfm.tr/*
// @match       *://*.lastfm.zh/*
// @match       *://*.musicbrainz.org/*
// @match       *://*.soundcloud.com/*
// @match       *://play.google.com/*
// @match       *://*.45cat.com/*
// @match       *://*.amazon.com/*
// @match       *://*.amazon.co.uk/*
// @match       *://*.amazon.ca/*
// @match       *://*.amazon.co.jp/*
// @match       *://*.amazon.com.au/*
// @match       *://*.amazon.com.br/*
// @match       *://*.amazon.com.mx/*
// @match       *://*.amazon.com.sa/*
// @match       *://*.amazon.cn/*
// @match       *://*.amazon.de/*
// @match       *://*.amazon.es/*
// @match       *://*.amazon.fr/*
// @match       *://*.amazon.in/*
// @match       *://*.amazon.it/*
// @match       *://*.amazon.nl/*
// @match       *://*.amazon.pk/*
// @match       *://*.cdbaby.com/*
// @match       *://*.jamendo.com/*
// @match       *://*.magnatune.com/*
// @author      Stig Nygaard, http://www.rockland.dk
// @homepageURL http://www.rockland.dk/userscript/misc/artgrab/
// @supportURL  http://www.rockland.dk/userscript/misc/artgrab/
// @grant       GM_registerMenuCommand
// @noframes
// ==/UserScript==

// Partly based on tips at http://wiki.musicbrainz.org/User:Nikki/CAA

// To use as bookmarklet:
// javascript:(function(){document.body.appendChild(document.createElement("script")).src="https://greasyfork.org/scripts/20771-stig-s-art-grabr/code/Stig's%20Art%20Grabr.user.js";}())

// CHANGELOG - The most important updates/versions:
var changelog = [
    {version: '2016.06.22.1', description: 'Re-adding musicdiner.com.'},
    {version: '2016.06.21.6', description: 'Preparing it to be able to run as a bookmarklet too...'},
    {version: '2016.06.20.0', description: '1st official release version.'},
    {version: '2016.06.19.1', description: 'Updated/fixed support for last.fm and bandcamp. Musicdinner is gone, but support for fnd.io and labs.stephenou.com/itunes added instead.'},
    {version: '2016.06.19.0', description: 'First userscript version (Converted from my old BCA bookmarklet).'}
];

function runGrabr() {
    var DEBUG = false;
    var log = function(s) {
        if (DEBUG && window.console) {
            window.console.log(s);
        }
    };
    // [ page pattern, search for img patterns, replace this, with this ]
    var a = [[/45cat\./, /-s\.jpg/i, /-s\.jpg/gi, ".jpg"],
        [/45cat\./, /-s\.png/i, /-s\.png/gi, ".png"],
        [/allmusic\./, /\/JPG_\d{3}\//i, /\/JPG_\d{3}\//gi, "/JPG_1080/"],
        [/amazon\./, /\._[A-Z]{2}\d{3}_[\w_,-]*\.jpg/i, /\._[A-Z]{2}\d{3}_[\w_,-]*\.jpg/gi, ".jpg"],
        [/amazon\./, /\._[A-Z]{2}\d{3}_[\w_,-]*\.png/i, /\._[A-Z]{2}\d{3}_[\w_,-]*\.png/gi, ".png"],
        [/bandcamp\./, /_\d{1,2}\.jpg/i, /_\d{1,2}\.jpg/gi, "_0.jpg"],
        [/bandcamp\./, /_\d{1,2}\.png/i, /_\d{1,2}\.png/gi, "_0.png"],
        [/cdbaby\./, /images\..*_small\.[jpgn]{3}/i, /_small\./gi, "."],
        [/cdbaby\./, /images\..*\.jpg/i, /\.jpg/gi, "_large.jpg"],
        [/cdbaby\./, /images\..*\.png/i, /\.png/gi, "_large.png"],
        [/fnd\.io/, /\/\d{2,}x\d{2,}bb/i, /\/\d{2,}x\d{2,}bb/gi, "/1200x1200bb"],
        [/itunes\.apple\./, /1\d0x1\d0\./i, /1\d0x1\d0\./gi, "1200x1200."],
        [/jamendo\./, /1\.\d00\.jpg/i, /1\.\d00\.jpg/gi, "1.0.jpg"],
        [/jamendo\./, /1\.\d00\.png/i, /1\.\d00\.png/gi, "1.0.png"],
        [/labs\.stephenou\.com/, /\/\d{2,3}x\d{2,3}bb/i, /\/\d{2,3}x\d{2,3}bb/gi, "/1200x1200bb"],
        [/last(fm)?\.[a-z]{2,3}/, /\.lst\.fm\/i\/u\/[a-zA-Z]*\d{2,}\w*\//i, /\.lst\.fm\/i\/u\/[a-z]*\d{2,}\w*\//gi, ".lst.fm/i/u/"],
        [/magnatune\./, /cover_\d{2,3}\./i, /cover_\d{2,3}\./gi, "cover."],
        [/musicbrainz\.org/, /_thumb\d{3}\./i, /_thumb\d{3}\./gi, "."],
        [/musicbrainz\.org/, /-\d{3}\.jpg/i, /-\d{3}\.jpg/gi, ".jpg"],
        [/musicbrainz\.org/, /-\d{3}\.png/i, /-\d{3}\.png/gi, ".png"],
        [/musicdiner\./, /\/\d{2,3}x\d{2,3}bb/i, /\/\d{2,3}x\d{2,3}bb/gi, "/1200x1200bb"],
        [/soundcloud\./, /t\d\d0x\d\d0\./i, /t\d\d0x\d\d0\./gi, "original."],
        [/play\.google\.com/, /googleusercontent\.com.*\=w\d{3}/, /\=w\d{3}$/, "=w1200"]];
        /* https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/ */
    var aEv = function (e,ev,f,c) {
        c=(c)?c:false;
        if(e.addEventListener) {
            e.addEventListener(ev,f,c)
        } else if(e.attachEvent) {
            e.attachEvent("on"+ev,f)
        } else {
            e["on"+ev]=f
        }
    };
    var w = null, n = 0, m = 20, d = document;
    if (d.location.hostname.search(/soundcloud\./) > -1) {
        spans = document.querySelectorAll("span[style*=background-image]");
        for (i = 0; i < spans.length; i++) {
            if (spans[i].style.backgroundImage) {
                imgsrc = spans[i].style.backgroundImage.match(/url[\(\"\u0027]+([^\"\u0027\)]*)[\)\"\u0027]+/)[1];
                if ((spans[i].getElementsByTagName("img").length == 0) && (imgsrc.match(/t[\d]{3}x[\d]{3}\./) != null)) {
                    spans[i].innerHTML = "<img src=\u0027" + imgsrc + "\u0027 alt=\u0027\u0027 style=\u0027width:200px;height:200px;border:none\u0027 />";
                }
            }
        }
    }
    log('Activated while on ' + d.location.hostname);
    o:
    for (var v = 0; v < a.length; v++) {
        if (d.location.hostname.search(a[v][0]) > -1) {
            log('Running on ' + d.location.hostname);
            w = a[v];
            var l = d.getElementsByTagName("img");
            if (l) {
                log('Found ' + l.length + ' image tags');
                for (var i = 0; i < l.length; i++) {
                    if ((l[i].src).search(w[1]) > -1) {
                        l[i].style.border = "1px #FB0 solid";
                        if (l[i].naturalWidth) {
                            l[i].onmouseover = function () {
                                this.title = "" + this.naturalWidth + "x" + this.naturalHeight
                            };
                        }
                        aEv(l[i], "load", function () {
                            if (this.style) {
                                this.style.borderColor = "#F00";
                                if (this.naturalWidth && this.naturalWidth > 999) {
                                    this.style.borderWidth = "2px"
                                }
                            }
                        });
                        aEv(l[i], "click", function () {
                            if (this.src) {
                                location = this.src
                            }
                        });
                        l[i].src = l[i].src.replace(w[2], w[3]);
                        n++;
                        if (n == m) {
                            if (confirm("" + n + " images requested. Continue?")) {
                                m = m + 20;
                            } else {
                                break o;
                            }
                        }
                    }
                }
            }
        }
    }
    if (w == null) {
        log('No hits found...');
    }
    return void(0);
}

if (typeof GM_registerMenuCommand === 'function') {
    // running as userscript - setting up menu item
    GM_registerMenuCommand("Search big size cover art", runGrabr, "a");
} else {
    // started from bookmarklet
    runGrabr();
}