Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Review Indexing Script
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description Indexing Reviews for https://fanlore.org/w/index.php?title=Dreaming_of_Sunshine
- // @author You
- // @match https://www.fanfiction.net/r/*
- // @grant none
- // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
- // ==/UserScript==
- (function() {
- 'use strict';
- Date.prototype.getMonthName = function(lang) {
- lang = lang && (lang in Date.locale) ? lang : 'en';
- return Date.locale[lang].month_names[this.getMonth()];
- };
- Date.prototype.getMonthNameShort = function(lang) {
- lang = lang && (lang in Date.locale) ? lang : 'en';
- return Date.locale[lang].month_names_short[this.getMonth()];
- };
- Date.locale = {
- en: {
- month_names: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
- month_names_short: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
- }
- };
- // Adding a function to arrays to get the last element.
- if (!Array.prototype.last){
- Array.prototype.last = function(){
- return this[this.length - 1];
- };
- };
- // Adding the format function to Strings.
- String.prototype.format = function() {
- var formatted = this;
- for (var i = 0; i < arguments.length; i++) {
- var regexp = new RegExp('\\{'+i+'\\}', 'gi');
- formatted = formatted.replace(regexp, arguments[i]);
- }
- return formatted;
- };
- // There's no where on the page that has the author information for the story. Could potentially load up another page, but eh.
- // Set this value if you want to automate it; otherwise leave it as is and search/replace later.
- var author = "(AUTHOR)"
- // Get Page URL
- var pageURL = self.location;
- // find the table element containing the reviews
- var reviewTable = $('.table')[0];
- // Get the story title - table . thead . tr . th . a(href) - 'https://www.fanfiction.net/s/7347955/1/Dreaming-of-Sunshine'
- var storyTitleHRef = reviewTable.children[0].children[0].children[0].children[1].href;
- var storyTitle = storyTitleHRef.split('/').last();
- // get the list of individual reviews - table . tbody . list<tr>
- var reviews = reviewTable.children[1].children;
- for(let i = 0; i < reviews.length; i++) {
- // Get the attributes we want
- // Small... thing. Contains date and chapter
- var chapter = $(reviews[i].children[0]).children('small')[0].textContent.split('.')[0].trim();
- var date = new Date(0);
- date.setUTCSeconds(parseInt($(reviews[i].children[0]).children('small')[0].children[0].dataset.xutime));
- // Username is either just text if it's anon, or this value is blank and the next element is an aref
- var username = reviews[i].children[0].childNodes[2].textContent.trim();
- if(username === "") {
- username = reviews[i].children[0].childNodes[3].href.split('/').last();
- }
- var indexString = "{0}, [{1} {2} by {3} - Review for {4}] Posted {5} {6} {7}".format(username, pageURL, storyTitle, author, chapter, date.getDate(), date.getMonthName(), date.getFullYear());
- var indexSpan = "<span style='color:gray;font-style:italic'>" + indexString + "</span>";
- reviews[i].children[0].innerHTML += indexSpan;
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement