Selbi

Remaining Words

Dec 5th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. // ==UserScript==
  2. // @name FIMFiction - Remaining Words and Reading Time
  3. // @namespace Selbi
  4. // @include http*://fimfiction.net/*
  5. // @include http*://www.fimfiction.net/*
  6. // @version 2.1
  7. // ==/UserScript==
  8.  
  9. ///////////////////
  10. // Read time is calculated with a base of 10000 words in 53 minutes (~188 Words Per Minute) (0:53:16:58 - Shades - 10029).
  11. var WPM = 188;
  12. // This is my personal reading speed. Feel free to change it to your liking.
  13. ///////////////////
  14.  
  15. var words, readstax, chapterstotal, rege, firstwords, currentstory=0, total, totalundread, currentwords, timeleft, totaltime, chaptersremaining, percentage, int, intx, block1, block2, block3;
  16. var alluls = document.getElementsByTagName('ul');
  17. for (var int=0; int<alluls.length; int++) {
  18. if (alluls[int].className == "chapters") {
  19. words = alluls[int].getElementsByClassName('word_count');
  20. rege = new RegExp("[0-9,]+");
  21. totalwordsX = parseInt(rege.exec(words[words.length-1].innerHTML)[0].replace(",",""));
  22. readstax = [];
  23. chapterstotal = 0;
  24. chaptersremaining = 0;
  25. $("ul.chapters:eq(" + currentstory + ") .chapter-read-icon").each(function() {
  26. if ($(this).hasClass("chapter-read")) {
  27. readstax[chapterstotal] = false;
  28. chapterstotal++;
  29. chaptersremaining++;
  30. } else {
  31. readstax[chapterstotal] = true;
  32. chapterstotal++;
  33. }
  34. });
  35. currentstory++;
  36. firstwords = parseInt(rege.exec(words[0].innerHTML)[0].replace(",",""));
  37. total = "0";
  38. totalunread = "0";
  39. currentwords = "";
  40. for (intx=0; intx<(words.length-1);intx++) {
  41. currentwords = parseInt(rege.exec(words[intx].innerHTML)[0].replace(",",""));
  42. total = parseInt(total) + parseInt(currentwords);
  43. if (readstax[intx] == true) {
  44. totalunread = parseInt(totalunread) + parseInt(currentwords);
  45. }
  46. //if (parseInt(currentwords) == 0) {chapterstotal--;} // UNCOMMENT TO IGNORE EMPTY CHAPTERS
  47. //if (words.length > 2) {
  48. words[intx].innerHTML = '<acronym style="border-bottom: 1px dashed #999;" title="' + ((Math.round((currentwords/totalwordsX)*10000))/100).toFixed(2) + '%"><span style="font-size:80%">[~' + convertToTime(currentwords) + "]</span></acronym>&nbsp;&nbsp;" + words[intx].innerHTML;
  49.  
  50. //}
  51. }
  52. timeleft = convertToTime(totalunread);
  53. totaltime = convertToTime(total);
  54.  
  55. percentage = ((Math.round((totalunread/total)*10000))/100).toFixed(2);
  56. Npercentage = ((Math.round((1-(totalunread/total))*10000))/100).toFixed(2);
  57. chppercent = ((Math.round((chaptersremaining/chapterstotal)*10000))/100).toFixed(2);
  58.  
  59. var sep = "&nbsp;&nbsp;&nbsp;";
  60. var sep2 = '<acronym title="' + numberWithCommas(total) + '">&nbsp;&nbsp;</acronym>';
  61. var B_ProgressBar = '<span style="border-style:solid;border-width:1px;background-color:#FFFFFF;width:100px;display:inline-block;" onmouseover="PBtext' + int + '.innerHTML=\'' + chaptersremaining + "/" + chapterstotal + '\';PBgreen' + int + '.style.width=\'' + chppercent + '%\'" onmouseout="PBtext' + int + '.innerHTML=\'' + Npercentage + '%\';PBgreen' + int + '.style.width=\'' + Npercentage + '%\'"><span id="PBgreen' + int + '" style="background-color:#01CA24;width:' + Npercentage + '%;display:inline-block;"><span id="PBtext' + int + '" style="display:inline-block;">' + Npercentage + '%</span></span></span>';
  62. var B_AvgWords = 'Avg. words/chapter: ' + Math.ceil(total/chapterstotal);
  63. var B_TotalTime = '<acronym style="border-bottom: 1px dashed #999;" title="' + B_AvgWords + '">[~' + totaltime + "]</acronym>";
  64. var B_TotalTime_Remaining = '<acronym style="border-bottom: 1px dashed #999;" title="Time spent so far: ~' + convertToTime(total-totalunread) + '">[~' + timeleft + " / ~" + totaltime + ']</acronym>';
  65. var B_Status_Read = "&#10004;" + " All chapters read.";
  66. var B_Status_Unread = "&#10008;" + " Unread.";
  67. var B_Status_NullStory = "This story has no words.";
  68. var B_RemainingWords = '<i><acronym style="border-bottom: 1px dashed #999;" title="' + numberWithCommas(total-totalunread) +' words read --- ' + B_AvgWords + '">' + numberWithCommas(totalunread) + "</acronym></i>";
  69. var B_RestHTML = words[words.length-1].innerHTML;
  70. var WordBlockHTML = words[words.length-1];
  71.  
  72. if (isNaN(percentage)) { // empty story
  73. WordBlockHTML.innerHTML = B_Status_NullStory + sep + B_RestHTML;
  74. } else if (Npercentage == 0) { // unread story
  75. WordBlockHTML.innerHTML = B_Status_Unread + sep + B_ProgressBar + sep + B_TotalTime + sep2 + B_RestHTML;
  76. } else if (Npercentage == 100) { // read story
  77. WordBlockHTML.innerHTML = B_Status_Read + sep + B_ProgressBar + sep + B_TotalTime + sep2 + B_RestHTML;
  78. } else { // in-progress story
  79. WordBlockHTML.innerHTML = B_ProgressBar + sep + B_TotalTime_Remaining + sep + B_RemainingWords + sep + "/" + sep2 + B_RestHTML;
  80. }
  81. }
  82. }
  83.  
  84. function numberWithCommas(x) {
  85. return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  86. }
  87.  
  88. function convertToTime(x) {
  89. var time = (Math.ceil(x/WPM));
  90. if (time > 60) {
  91. time = ((Math.ceil(time/6))/10).toFixed(1) + " h";
  92. } else {
  93. time += " min";
  94. }
  95. return time;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment