Imgur numbered images

Numbers images in Imgur galleries

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Imgur numbered images
// @description Numbers images in Imgur galleries
// @namespace   ouroborus.org
// @version     1
// @match       https://imgur.com/gallery/*
// @grant       none
// ==/UserScript==
var script = document.createElement("script");
document.head.append(script);
script.textContent = `
function numberItems(images) {
  var s = document.getElementById('numberItems');
  if(s) s.parentNode.removeChild(s);
  var rules = [
    '.post-image-container{position:relative;}',
    '.post-image-container:after{position:absolute;top:0.5em;right:100%;padding:0.5em;border-radius:3px 0 0 3px;background:#2c2f34;}'
  ];
  for(var i = 0; i < images.length; i++) {
    rules.push(\`[id="\${images[i].hash}"]:after{content:"#\${i+1}\\\";}\`);
  }
  s = document.createElement('style');
  s.setAttribute('id','numberItems');
  s.appendChild(document.createTextNode(rules.join('\\n')));
  document.head.appendChild(s);
  waitForChange(numberItems);
}
var hash = null;
function waitForChange(fn) {
  let image = Imgur.Gallery._instance.imgurInsideNav._.image;
  if(hash != image.hash && image.album_images) {
    hash = image.hash;
    fn(image.album_images.images || image.album_images);
  } else {
    setTimeout(function() { waitForChange(fn) }, 50)
  }
};
waitForChange(numberItems);
`;