Last active
February 26, 2024 07:36
-
-
Save SimDing/dd46389817c3f999944a to your computer and use it in GitHub Desktop.
Greasemonkey/Tampermonkey script: Ermöglicht das automatische Anlegen von Lesezeichen für Manga auf der Seite proxer.me
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Proxer Auto-Lesezeichen | |
// @namespace de.093r.proxer | |
// @description Ermöglicht das automatische Anlegen von Lesezeichen für Manga auf der Seite proxer.me | |
// @include http://proxer.me/* | |
// @include https://proxer.me/* | |
// @version 2.3 | |
// @downloadURL https://gist.github.com/SimDing/dd46389817c3f999944a/raw/proxer_auto_bookmark.user.js | |
// @grant none | |
// @history 2.3 Improved storage integrity | |
// @history 2.2 Added Chrome support | |
// ==/UserScript== | |
function main() { | |
// labels | |
var btn_txt_on = 'Auto-Lesezeichen: AN'; | |
var btn_txt_off = 'Auto-Lesezeichen: AUS'; | |
var confirm_txt = 'Es existiert schon ein Lesezeichen von Kapitel {0}. Soll es mit dem aktuellen ({1}) überschrieben werden?'; | |
// warn before overriding a bookmark with one that is not the next chapter | |
var overwrite_warning = true; // true/false | |
var on_by_default = true; // true/false | |
var update_DB_after = 10 * 60 * 1000; // milliseconds | |
//internal properties - edit if u know what u do | |
var bookmark_search = '.reminder[title="reminder_this"]'; | |
var btn_id = 'autoReminderBtn'; | |
var btn_html = ' <a id="'.concat(btn_id, '" class="menu" href="javascript:void(0);"></a>'); | |
var storage = window.sessionStorage; //might as well use localStorage | |
var LAST_BOOKMARK_FIELD_NAME = 'lastMark'; | |
if (typeof (storage) === 'undefined') { | |
alert('Your browser sucks. Auto-bookmark does not work.'); | |
throw new Error(); | |
} | |
function sformat(format) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
return format.replace(/{(\d+)}/g, function(match, number) { | |
return typeof args[number] != 'undefined'? args[number] : match; | |
}); | |
} | |
function ProxerMangaURLInfo(url) { | |
var parts = url.replace(/^.*\/\/[^\/]+/, '').substr(1).replace(/\?.*/, '').split('/'); | |
this.realm = parts[0]; | |
this.series = parts[1]; | |
this.chapter = parseInt(parts[2]); | |
} | |
var refURI = new ProxerMangaURLInfo(document.referrer); | |
var curURI = new ProxerMangaURLInfo(window.location.href); | |
function StorageAccessor() { | |
if (!this.isUpToDate()) { | |
this.update(); | |
} | |
} | |
StorageAccessor.prototype.lastUpdate = function () { | |
if (!storage.lastUpt) | |
storage.lastUpt = 0; | |
return parseInt(storage.lastUpt); | |
}; | |
StorageAccessor.prototype.isUpToDate = function () { | |
var millis = new Date().valueOf(); | |
return millis < this.lastUpdate() + update_DB_after; | |
}; | |
StorageAccessor.prototype.mk_invalid = function () { | |
storage.lastUpt = 0; | |
}; | |
StorageAccessor.prototype.ensureUpToDate = function () { | |
if (!this.isUpToDate()) { | |
this.update(false); | |
} | |
}; | |
StorageAccessor.prototype.put = function (info) { | |
var fieldName = LAST_BOOKMARK_FIELD_NAME.concat(info.series); | |
storage.setItem(fieldName, info.chapter); | |
}; | |
StorageAccessor.prototype.get = function (seriesName) { | |
this.ensureUpToDate(); | |
var chapter = storage.getItem(LAST_BOOKMARK_FIELD_NAME.concat(seriesName)); | |
if (chapter) { | |
return parseInt(chapter); | |
} else { | |
return -1; | |
} | |
}; | |
StorageAccessor.prototype.contains = function (seriesName) { | |
this.ensureUpToDate(); | |
var chapter = storage.getItem(LAST_BOOKMARK_FIELD_NAME.concat(seriesName)); | |
if (chapter) { | |
return true; | |
} else { | |
return false; | |
} | |
}; | |
StorageAccessor.prototype.isActive = function () { | |
if (storage.isActive) { | |
if (storage.isActive == 'true') { | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
return on_by_default; | |
} | |
}; | |
StorageAccessor.prototype.setActive = function (bm_active) { | |
storage.isActive = bm_active; | |
}; | |
StorageAccessor.prototype.update = function (asyncCall = true) { | |
var bmStorage = this; | |
$.ajax({ | |
url: '/ucp?s=reminder&format=raw', | |
type: 'get', | |
dataType: 'html', | |
success: function (data) { | |
var on = bmStorage.isActive(); | |
storage.clear(); | |
var _html = $(data); | |
var mangaTable = _html.find('td:last-child > table'); | |
var chapterLinks = mangaTable.find('a.tip'); | |
chapterLinks.each (function (num) { | |
var info = new ProxerMangaURLInfo(this.href); | |
bmStorage.put(info); | |
}); | |
storage.lastUpt = new Date().valueOf(); | |
bmStorage.setActive(on); | |
}, | |
async: asyncCall | |
}); | |
}; | |
var storageAcc = new StorageAccessor(); | |
if (curURI.realm === 'ucp') { | |
//make storage invalid if delete bookmark button is pressed | |
$(document).ready(function() { | |
$('.deleteReminder').click(function () { | |
storageAcc.mk_invalid(); | |
}); | |
}); | |
} | |
if (curURI.realm !== 'chapter') { | |
return; | |
} | |
$(document).ready(function () { | |
//make storage invalid if bookmark button is pressed | |
$('.reminder').click(function () { | |
storageAcc.mk_invalid(); | |
}); | |
var reminderBtn = $(bookmark_search); | |
// Add button | |
reminderBtn.parent().append(btn_html); | |
var autoReminderBtn = $('#'.concat(btn_id)); | |
function updateLabel() { | |
if (storageAcc.isActive()) { | |
autoReminderBtn.html(btn_txt_on); | |
} else { | |
autoReminderBtn.html(btn_txt_off); | |
} | |
} | |
updateLabel(); | |
autoReminderBtn.click(function () { | |
storageAcc.setActive(!storageAcc.isActive()); | |
updateLabel(); | |
}); | |
//Auto-bookmark | |
if (!storageAcc.isActive() || !storageAcc.contains(curURI.series)) { | |
return; | |
} | |
if (refURI.realm === 'read' | |
&& curURI.realm === 'chapter' | |
&& refURI.series === curURI.series | |
&& refURI.chapter === curURI.chapter - 1) { | |
var currentMark = storageAcc.get(curURI.series); | |
if (curURI.chapter === currentMark) { | |
return; | |
} | |
if (overwrite_warning && curURI.chapter - 1 !== currentMark) { | |
if (!confirm(sformat(confirm_txt, currentMark, curURI.chapter))) { | |
return; | |
} | |
} | |
reminderBtn.click(); | |
storageAcc.put(curURI); | |
} | |
}); | |
} | |
if (typeof $ === 'undefined') { | |
//chrome | |
var script = document.createElement('script'); | |
script.textContent = '(' + main.toString() + ')();'; | |
document.body.appendChild(script); | |
} else { | |
//firefox | |
main(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment