GooglePlay direct screenshot links

Shows all the screenshots without the scrollbox and adds direct links for fullsized versions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          GooglePlay direct screenshot links
// @description   Shows all the screenshots without the scrollbox and adds direct links for fullsized versions
// @include       https://play.google.com/store*
// @version       1.0.10
// @author        wOxxOm
// @namespace     wOxxOm.scripts
// @license       MIT License
// @run-at        document-body
// ==/UserScript==

const GALLERY_ATTR = 'data-slideable-portion-heuristic-width';
const GALLERY_SELECTOR = `[${GALLERY_ATTR}]`;
const FULL_HEIGHT = 2160;
const PREVIEW_HEIGHT = 418;

const mo = new MutationObserver(onMutation);
const observe = () => mo.observe(document, {
  subtree: true,
  childList: true,
  attributes: true,
  attributeFilter: ['style', 'jsdata'],
});
let throttled;
onMutation([{
  addedNodes: [document.body],
  target: document.documentElement,
}]);
observe();
// addEventListener('pageshow', replaceGallery);

async function onMutation(mutations) {
  if (!throttled) {
    throttled = true;
    // await 0;
    replaceGallery();
    throttled = false;
  }
}

function replaceGallery() {
  const node = document.querySelector(GALLERY_SELECTOR);
  if (!node) return;
  mo.disconnect();
  const container = $new('div', {
    style: 'text-align: center',
  });
  const contWidth = node.getBoundingClientRect().width;
  for (const img of node.getElementsByTagName('img')) {
    if (img.nextElementSibling) {
      container.appendChild(img.parentNode);
    } else {
      const src =
        img.dataset.src ||
        (img.srcset || '').match(/https:\S+|$/)[0] ||
        img.src ||
        '';
      const width = img.height && Math.round(PREVIEW_HEIGHT / img.height * img.width);
      const a = $new('a', {
        style: 'margin: 0 4px 4px 0; display: inline-block;',
        href: src.replace(/=.*/, `=h${FULL_HEIGHT}`),
        target: '_blank',
      }, [
        $new('img', Object.assign({
          src: src.replace(/=.*/, `=w${contWidth}-h${PREVIEW_HEIGHT}-rw`),
          height: PREVIEW_HEIGHT,
        }, width && width < contWidth && {
          width,
        })),
      ]);
      container.appendChild(a);
    }
  }
  node.parentNode.replaceWith(container);
  observe();
}

function $new(tag, props, children) {
  const el = document.createElement(tag);
  Object.assign(el, props);
  if (children)
    el.append(...children.filter(Boolean));
  return el;
}