Myself 觀看紀錄小工具

幫你紀錄上次看到第幾話

  1. // ==UserScript==
  2. // @name Myself 觀看紀錄小工具
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.0
  5. // @description 幫你紀錄上次看到第幾話
  6. // @author xu3u04u48
  7. // @match *://myself-bbs.com/thread-*.html
  8. // @match *://myself-bbs.com/forum.php?mod=viewthread&tid=*
  9. // @icon https://www.google.com/s2/favicons?domain=myself-bbs.com
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const url_pathname_regex = /-(\d*)-|tid=(\d*)/gm;
  17. const url_pathname = location.href
  18. let page_val = ""
  19. let m;
  20. while ((m = url_pathname_regex.exec(url_pathname)) !== null) {
  21. m.forEach((match, groupIndex) => {
  22. if(match !== undefined)
  23. page_val = match
  24. });
  25. }
  26.  
  27.  
  28. var view_history = []
  29.  
  30. jQuery(".bm_h > h2").text("劇集列表 上次看到 第" + get_episode() + "話")
  31. jQuery(".bm_h > h2").click(function(e){
  32. if(get_episode() >= 1 ){
  33. jq('.main_list').scrollTop((get_episode() - 1)*31);
  34. }
  35. })
  36.  
  37. jQuery(".main_list a").click(function(e){
  38. const episode_regex = /第 (\d*) 話/gm;
  39. const episode = episode_regex.exec(this.text)[1]
  40. add_view_history(episode)
  41. jQuery(".bm_h > h2").text("劇集列表 上次看到 第" + Number(episode) + "話")
  42. })
  43.  
  44. function add_view_history(episode){
  45. var discover = false
  46. var get_view_history = JSON.parse(localStorage.getItem("view_history"))
  47. if(get_view_history != null && get_view_history.length != 0){
  48. for (var a = 0; a <= get_view_history.length - 1; a++) {
  49. if(get_view_history[a].index == page_val){
  50. get_view_history[a].episode = episode
  51. discover = true
  52. }
  53. }
  54. if(!discover)get_view_history.push({index:page_val, episode:episode})
  55. localStorage.setItem("view_history", JSON.stringify(get_view_history))
  56. }else{
  57. view_history.push({index:page_val, episode:episode})
  58. localStorage.setItem("view_history", JSON.stringify(view_history))
  59. }
  60. }
  61.  
  62. function get_episode(){
  63. var get_episode = ""
  64. var get_view_history = JSON.parse(localStorage.getItem("view_history"))
  65. if(get_view_history != null && get_view_history.length != 0){
  66. for (var a = 0; a <= get_view_history.length - 1; a++) {
  67. if(get_view_history[a].index == page_val){
  68. get_episode = Number(get_view_history[a].episode)
  69. return get_episode
  70. }
  71. }
  72.  
  73. }
  74. return 0
  75. }
  76. })();