HPMOR Checklist

Adds a checkbox to each chapter. Stores checked history.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        HPMOR Checklist
// @namespace   http://jaredtylermiller.com
// @description Adds a checkbox to each chapter. Stores checked history.
// @include     http://hpmor.com/
// @include     http://hpmor.com/chapter/*
// @require     https://code.jquery.com/jquery-1.11.2.min.js
// @require     http://cdnjs.cloudflare.com/ajax/libs/store.js/1.3.14/store.min.js
// @version     1.0
// ==/UserScript==


// Grab chapter from URL if possible
var chapterPath = window.location.pathname.split("/")

// If so, let's store that we've read it in DB
if (chapterPath.length === 3) {
  var chapter = chapterPath[chapterPath.length -1]
  store.set(chapter, true)
}

// Add a checkbox to every chapter and check if it needed
$(".toclist a").each(function() {
  var link = $(this),
      chapter = link.closest("li").index()+1

  link.before("<input type='checkbox'>")
  saved = store.get(chapter)

  if (typeof saved !== "undefined") {
    link.siblings("input").prop("checked", saved)
  }
})

// Store in DB if we click a link
$(".toclist a").click(function(e) {
  e.preventDefault()
  var chapter = $(this).closest("li").index()+1,
      checkbox = $(this).find("input"),
      checked = checkbox.prop("checked")

  store.set(chapter, !checked)
  checkbox.prop("checked", !checked)
  window.location.href = $(this).attr("href")
})

// Store when clicking checkboxes
$(".toclist input").click(function(e) {
  var chapter = $(this).closest("li").index()+1,
      checked = $(this).prop("checked")

  store.set(chapter, checked)
})