DMM 增强

DMM

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         DMM 增强
// @namespace    http://tampermonkey.net/
// @version      0.2.0
// @author       targetlock
// @description  DMM
// @match        *://www.dmm.co.jp/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict'

  addNextAndPrevButton()
  keyboardShourtcut();

  function keyboardShourtcut() {
    document.addEventListener('keyup', e => {
      if (e.code === 'Period' && !e.ctrlKey && e.shiftKey && !e.metaKey) {
          document.querySelector('#nextCidButton').click()
      }
      if (e.code === 'Comma' && !e.ctrlKey && e.shiftKey && !e.metaKey) {
          document.querySelector('#prevCidButton').click()
      }
    })
  }

  function addNextAndPrevButton() {
    const header = document.querySelector('.hreview')
    const cid = getCid()
    if (header && cid) {
       const nextCid = getNextCid(cid)
       const nextHref = location.href.replace(/\/cid=(\w+)\//, `/cid=${nextCid}/`)
       header.insertAdjacentHTML('beforeend', `<a id="nextCidButton" href="${nextHref}" style="float: right; margin: 0 0 0 20px">${nextCid}</a>`)

       const prevCid = getPrevCid(cid)
       const prevHref = location.href.replace(/\/cid=(\w+)\//, `/cid=${prevCid}/`)
       header.insertAdjacentHTML('beforeend', `<a id="prevCidButton" href="${prevHref}" style="float: right; margin: 0 0 0 20px">${prevCid}</a>`)
    }
  }

  function getCid() {
    const result = /\/cid=(\w+)\//.exec(location.href)
    return result ? result[1] : null
  }

  function getPrevCid(cid) {
    const re = /(\d+)(\D*)$/
    const result = re.exec(cid)
    const number = result[1]
    const suffix = result[2]
    return cid.replace(re, parseInt(number) - 1) + suffix
  }

  function getNextCid(cid) {
    const re = /(\d+)(\D*)$/
    const result = re.exec(cid)
    console.log(result)
    const number = result[1]
    const suffix = result[2]
    return cid.replace(re, parseInt(number) + 1) + suffix
  }
})();