Greasy Fork

Greasy Fork is available in English.

Last Picture Show

Link last.fm artist/album images directly to the image page

当前为 2017-07-05 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name          Last Picture Show
// @description   Link last.fm artist/album images directly to the image page
// @author        chocolateboy
// @copyright     chocolateboy
// @namespace     https://github.com/chocolateboy/userscripts
// @version       1.0.2
// @license       GPL: http://www.gnu.org/copyleft/gpl.html
// @include       http://*.last.fm/*
// @include       https://*.last.fm/*
// @include       http://*.lastfm.tld/*
// @include       https://*.lastfm.tld/*
// @require       https://code.jquery.com/jquery-3.2.1.min.js
// @require       https://cdn.rawgit.com/eclecto/jQuery-onMutate/79bbb2b8caccabfc9b9ade046fe63f15f593fef6/src/jquery.onmutate.min.js
// @grant         GM_log
// ==/UserScript==

// XXX note: the unused grant is a workaround for a Greasemonkey bug:
// https://github.com/greasemonkey/greasemonkey/issues/1614

/*
Thumbnail:    https://lastfm-img2.akamaized.net/i/u/300x300/{imageId}.jpg
Picture page: https://www.last.fm/music/Artist+Name/+images/{imageId}

before:

    <div class="grid-items-cover-image js-link-block link-block">
        <div class="grid-items-cover-image-image">
            <img
                src="https://lastfm-img2.akamaized.net/i/u/300x300/1ce40dc1f3ec52cb78efb9f0ae54dddd.jpg"
                alt="Image for 'Ellie Goulding'"
            />
        </div>
        <div class="grid-items-item-details">
            <p class="grid-items-item-main-text">
                <a href="/music/Ellie+Goulding" class="link-block-target">Ellie Goulding</a>
            </p>
            <p class="grid-items-item-aux-text">
                1,783,906 <span class="stat-name">listeners</span>
            </p>
        </div>
        ...
    </div>

after:

    <div class="grid-items-cover-image js-link-block link-block">
        <div class="grid-items-cover-image-image">
            <!-- XXX wrap the image in a link -->
            <a href="/music/Ellie+Goulding/+images/1ce40dc1f3ec52cb78efb9f0ae54dddd">
                <img
                    src="https://lastfm-img2.akamaized.net/i/u/300x300/1ce40dc1f3ec52cb78efb9f0ae54dddd.jpg"
                    alt="Image for 'Ellie Goulding'"
                />
            </a>
        </div>
        <div class="grid-items-item-details">
            <p class="grid-items-item-main-text">
                <!-- XXX grab the path from here -->
                <a href="/music/Ellie+Goulding" class="link-block-target">Ellie Goulding</a>
            </p>
            <p class="grid-items-item-aux-text">
                1,783,906 <span class="stat-name">listeners</span>
            </p>
        </div>
        ...
    </div>
*/

function onItem ($items) {
    $items.each(function () {
        const $item = $(this)
        const $image = $item.find('.grid-items-cover-image-image img[src]')
        const imageId = $image.attr('src').match(/\/(\w+)\.\w+$/)[1]
        const path = $item.find('a.link-block-target[href]').attr('href')

        $image.wrap(`<a href="${path}/+images/${imageId}"></a>`)
    })
}

$.onCreate('.grid-items-cover-image', onItem, true /* multi */)