Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name FIMFiction - Remaining Words and Reading Time
- // @namespace Selbi, rewritten by Queue
- // @include http*://fimfiction.net/*
- // @include http*://www.fimfiction.net/*
- // @version 3
- // ==/UserScript==
- var wpm=188;
- var all_Unsorted_Lists = document.getElementsByTagName('ul');
- for (var i=0; i<all_Unsorted_Lists.length; i++)
- {
- if (all_Unsorted_Lists[i].className == "chapters")
- {
- //Grabs the elements of the word counts.
- var chapter_Word_Counts_By_Element=all_Unsorted_Lists[i].getElementsByClassName('word_count');
- //Grabs the elements, which display if a chapter has been read.
- var chapter_Read_Status = all_Unsorted_Lists[i].getElementsByClassName('chapter-read-icon');
- //We know how many chapters there are because we just grabbed them, so we're putting the number in a variable.
- var number_Of_Chapters=chapter_Read_Status.length;
- //We'll update these when we check which chapters have been read.
- var number_Of_Read_Chapters=0;
- var number_Of_Read_Words=0;
- //This will let us rip the actual word counts from the html of the word count elements.
- var word_Count_Regex = new RegExp("[0-9,]+");
- //This is where we'll store the word counts in number form.
- var int_Word_Counts=[];
- //This converts and stores the word counts to intergers.
- for(var ii=0;ii<chapter_Word_Counts_By_Element.length;ii++)
- {
- //This converts and stores the word counts to intergers.
- int_Word_Counts[ii]=parseInt(word_Count_Regex.exec(chapter_Word_Counts_By_Element[ii].innerHTML)[0].replace(",",""));
- //We only want the estimated time applied to the chapters, not the total, which is at the end of the list.
- if(ii<chapter_Word_Counts_By_Element.length-1)
- {
- //This posts the estimated reading time next to each chapter.
- var temp="[ "+convertToTime(int_Word_Counts[ii])+" ] "+chapter_Word_Counts_By_Element[ii].innerHTML;
- chapter_Word_Counts_By_Element[ii].innerHTML=temp;
- }
- }
- //Here we check which chapters have been read.
- for(var ii=0;ii<chapter_Read_Status.length;ii++)
- {
- //The check.
- if(chapter_Read_Status[ii].className=="chapter-read-icon chapter-read")
- {
- number_Of_Read_Chapters++;
- //Looks up the number of words in the chapter and adds it to the read total.
- number_Of_Read_Words+=int_Word_Counts[ii];
- }
- }
- //Grabs the total word count from the array.
- var total_Word_Count=int_Word_Counts[chapter_Word_Counts_By_Element.length-1];
- //Calculates the percentage read from the number of words read vs total words.
- var percentage_Read=(number_Of_Read_Words/total_Word_Count).toFixed(2)*100;
- //Builds the HTML for the final entry.
- var temp=percentage_Read+"% complete. "+number_Of_Read_Chapters+" chapters of "+number_Of_Chapters+" chapters read. [ "+convertToTime(number_Of_Read_Words)+" / "+ convertToTime(total_Word_Count)+" ] "+chapter_Word_Counts_By_Element[chapter_Word_Counts_By_Element.length-1].innerHTML;
- //Inserts the HTML.
- chapter_Word_Counts_By_Element[chapter_Word_Counts_By_Element.length-1].innerHTML=temp;
- }
- }
- //Selbi's function slightly modified for readability and formatting.
- function convertToTime(word_Count)
- {
- var read_Time = (Math.ceil(word_Count/wpm));
- var post_Time;
- if (read_Time > 60)
- {
- post_Time = "~ " + ((Math.ceil(read_Time/6))/10).toFixed(1) + " h";
- }
- else
- {
- post_Time ="~ " + read_Time + " min";
- }
- return post_Time;
- }
Advertisement
Add Comment
Please, Sign In to add comment