Wattpad+

Adds useful things to Wattpad

  1. // ==UserScript==
  2. // @name Wattpad+
  3. // @namespace wattpad.com
  4. // @version 0.1
  5. // @description Adds useful things to Wattpad
  6. // @author Herman Fassett
  7. // @include https://wattpad.com/*
  8. // @include https://www.wattpad.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. var data, part, reading = false;
  15. for (var i in window.prefetched) {
  16. if (i.match("part")) {
  17. reading = true;
  18. data = window.prefetched[i].data;
  19. part = i;
  20. // Display word count
  21. var stats = document.getElementsByClassName("story-stats")[0];
  22. var words = document.createElement("span");
  23. var inner = document.createElement("span");
  24. var text = document.createElement("p");
  25. text.innerText = data.wordCount + " words";
  26. inner.className = "fa fa-view fa-wp-grey";
  27. words.appendChild(inner);
  28. words.appendChild(text);
  29. stats.appendChild(words);
  30. }
  31. }
  32. document.onkeydown = function(e) {
  33. if (reading) {
  34. // Allow part navigation by arrow keys
  35. if (e.keyCode == 39) { // Right - Next part
  36. window.location = data.nextPart.url;
  37. }
  38. else if (e.keyCode == 37) { // Left
  39. var parts = data.group.parts;
  40. for (var i = 0; i < parts.length; i++) {
  41. if (parts[i].active && i > 0) {
  42. window.location = parts[i-1].url;
  43. }
  44. }
  45. }
  46. }
  47. };
  48. })();