Greasy Fork 还支持 简体中文。

TVMaze: add "Watched" button to calendar

Add "Mark as watched" button to calendar entries at TVMaze

  1. // ==UserScript==
  2. // @name TVMaze: add "Watched" button to calendar
  3. // @description Add "Mark as watched" button to calendar entries at TVMaze
  4. // @namespace BlackNullerNS
  5. // @include http*://www.tvmaze.com/calendar*
  6. // @version 1.2
  7. // ==/UserScript==
  8.  
  9. var btn = document.createElement('button');
  10. btn.innerHTML = '✓';
  11. btn.style.fontWeight = 'bold';
  12. btn.style.border = 0;
  13. btn.style.padding = '2px 4px';
  14. btn.style.background = 'transparent';
  15. btn.style.color = '#3C948B';
  16. btn.style.cursor = 'pointer';
  17. btn.setAttribute('title', 'Mark as watched');
  18.  
  19. var handler = function (e) {
  20. e.preventDefault();
  21.  
  22. var self = this,
  23. entry = this.parentNode.parentNode,
  24. link = entry.querySelector('a[href*="episodes/"]');
  25.  
  26. if (!link) {
  27. return false;
  28. }
  29.  
  30. var eid = link.getAttribute('href').split('episodes/')[1].split('/')[0];
  31. var url = '/watch/set?episode_id=' + eid;
  32. var csrf = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
  33.  
  34. var xhr = new XMLHttpRequest();
  35. xhr.open('POST', url);
  36. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  37. xhr.setRequestHeader('X-CSRF-Token', csrf);
  38.  
  39. xhr.addEventListener('load', function () {
  40. entry.classList.add('watched');
  41. self.remove();
  42. });
  43.  
  44. xhr.send("type=0");
  45. };
  46.  
  47. var mouseover = function () {
  48. this.style.color = '#cc0000';
  49. };
  50.  
  51. var mouseout = function () {
  52. this.style.color = '#3C948B';
  53. };
  54.  
  55. var cloned;
  56. var episodes = document.querySelectorAll(".entry:not(.watched)");
  57.  
  58. for (var i = 0, l = episodes.length; i < l; i++) {
  59. cloned = btn.cloneNode(true);
  60. cloned.addEventListener('click', handler);
  61. cloned.addEventListener('mouseover', mouseover);
  62. cloned.addEventListener('mouseout', mouseout);
  63.  
  64. episodes.item(i).firstElementChild.appendChild(cloned);
  65. }