AO3: Kudosed and seen history

Highlight or hide works you kudosed/marked as seen.

目前为 2015-08-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name AO3: Kudosed and seen history
  3. // @description Highlight or hide works you kudosed/marked as seen.
  4. // @namespace https://gf.qytechs.cn/scripts/5835-ao3-kudosed-and-seen-history
  5. // @author Min
  6. // @version 1.5
  7. // @history 1.5 - import/export seen list
  8. // @history 1.4 - thinner stripes, remembers bookmarks you left
  9. // @history 1.3 - option to collapse blurbs of seen works
  10. // @history 1.2.1 - double click on date marks work as seen
  11. // @history 1.2 - check for bookmarks you left, changes to the menu
  12. // @grant none
  13. // @include http://archiveofourown.org/*
  14. // @include https://archiveofourown.org/*
  15. // ==/UserScript==
  16.  
  17.  
  18. (function($) {
  19. if (typeof(Storage) !== 'undefined') {
  20. var debug = false;
  21. // newest more-or-less major version, for the update notice
  22. var current_version = 1.5;
  23. var username = localStorage.getItem('kudoshistory_username');
  24. // if there's no saved username, look for it on the page or ask
  25. if (!username) {
  26. localStorage.setItem('kudoshistory_lastver', current_version);
  27. var userlink = $('#greeting').find('[href^="/users/"]');
  28. if (userlink.length) {
  29. var userlink_parts = userlink.attr('href').split('/');
  30. var username = userlink_parts[2];
  31. localStorage.setItem('kudoshistory_username', username);
  32. }
  33. else {
  34. var username = prompt('AO3: Kudosed and seen history\n\nYour AO3 username:');
  35. localStorage.setItem('kudoshistory_username', username);
  36. }
  37. }
  38. // check the 'hide seen works' setting
  39. var hide_seen = 0;
  40. var hide_seen_set = localStorage.getItem('kudoshistory_hide');
  41. switch (hide_seen_set) {
  42. case 'yes':
  43. hide_seen = 1;
  44. break;
  45. case 'collapse':
  46. hide_seen = 2;
  47. }
  48. // check the 'mark as seen on open' setting
  49. var auto_seen = false;
  50. var auto_seen_set = localStorage.getItem('kudoshistory_autoseen');
  51. if (auto_seen_set == 'yes') {
  52. auto_seen = true;
  53. }
  54. // check the 'highlight bookmarked' setting
  55. var highlight_bookmarked = true;
  56. var highlight_bookmarked_set = localStorage.getItem('kudoshistory_highlight_bookmarked');
  57. if (highlight_bookmarked_set == 'no') {
  58. highlight_bookmarked = false;
  59. }
  60. // uncomment the next four lines if you need to clear your local lists (then comment them again after refreshing the page once)
  61. // localStorage.removeItem('kudoshistory_kudosed');
  62. // localStorage.removeItem('kudoshistory_checked');
  63. // localStorage.removeItem('kudoshistory_seen');
  64. // localStorage.removeItem('kudoshistory_bookmarked');
  65.  
  66. var list_kudosed = localStorage.getItem('kudoshistory_kudosed');
  67. var list_checked = localStorage.getItem('kudoshistory_checked');
  68. var list_seen = localStorage.getItem('kudoshistory_seen');
  69. var list_bookmarked = localStorage.getItem('kudoshistory_bookmarked');
  70. if (!list_kudosed) { var list_kudosed = ','; }
  71. if (!list_checked) { var list_checked = ','; }
  72. if (!list_seen) { var list_seen = ','; }
  73. if (!list_bookmarked) { var list_bookmarked = ','; }
  74. $(document).ajaxStop(function() {
  75. localStorage.setItem('kudoshistory_kudosed', list_kudosed);
  76. localStorage.setItem('kudoshistory_checked', list_checked);
  77. localStorage.setItem('kudoshistory_seen', list_seen);
  78. localStorage.setItem('kudoshistory_bookmarked', list_bookmarked);
  79. });
  80. var style = $('style').filter(':last');
  81. if (!style.length) { style = $('<style type="text/css"></style>').appendTo($('head')); }
  82. // add css rules for kudosed works
  83. addCss(0);
  84. // if there's a list of works or bookmarks, add menu
  85. var found_blurbs = $('li.work.blurb').add('li.bookmark.blurb');
  86. if (found_blurbs.length) {
  87. addSeenMenu();
  88. }
  89. // if it's the first time after an update
  90. addNotice();
  91. // for each work blurb
  92. $('li.work.blurb').not('.deleted').each(function() {
  93. // get work id
  94. var work_id = $(this).attr('id').replace('work_', '');
  95. debug && console.log('works loop ' + work_id);
  96. blurbCheck(work_id, 'work_' + work_id, $(this), true);
  97. // double click on date marks work as seen
  98. var work_date = $(this).not('.marked-seen').not('.has-kudos').find('p.datetime');
  99. if (work_date.length) {
  100. debug && console.log('set date click ' + work_id);
  101. work_date.one('dblclick', function() {
  102. list_seen = localStorage.getItem('kudoshistory_seen');
  103. list_seen = ',' + work_id + list_seen;
  104. localStorage.setItem('kudoshistory_seen', list_seen);
  105. $('#work_' + work_id).addClass('marked-seen');
  106. });
  107. }
  108. });
  109. // for each bookmark blurb
  110. $('li.bookmark.blurb').not('.deleted').each(function() {
  111. // get bookmark and work ids
  112. var bookmark_id = $(this).attr('id');
  113. var work_link = $(this).find('h4 a:first').attr('href');
  114. // if it's not a deleted work and not a series bookmark
  115. if (!!work_link && work_link.indexOf('series') == -1) {
  116. var work_id = work_link.split('/').pop();
  117. debug && console.log('bookmarks loop ' + work_id + ' ' + bookmark_id);
  118. // if it's your own bookmark
  119. var own_bookmark = $(this).find('div.own.user.module.group');
  120. if (own_bookmark.length) {
  121. list_bookmarked = ',' + work_id + list_bookmarked.replace(',' + work_id + ',', ',');
  122. $(this).addClass('is-bookmarked');
  123. blurbCheck(work_id, bookmark_id, $(this), false);
  124. own_bookmark.find('a[href$="/confirm_delete"]').click(function() {
  125. list_bookmarked = localStorage.getItem('kudoshistory_bookmarked');
  126. list_bookmarked = list_bookmarked.replace(',' + work_id + ',', ',');
  127. $('#' + bookmark_id).removeClass('is-bookmarked');
  128. localStorage.setItem('kudoshistory_bookmarked', list_bookmarked);
  129. });
  130. }
  131. else {
  132. blurbCheck(work_id, bookmark_id, $(this), true);
  133. }
  134. }
  135. });
  136. // if it's a work page
  137. if ($('#workskin').length) {
  138. // get work id
  139. var url_parts = location.pathname.split('/');
  140. var work_id = url_parts[url_parts.indexOf('works')+1];
  141. debug && console.log('work_id ' + work_id);
  142. // check if work id is on the seen list
  143. var is_seen = list_seen.indexOf(',' + work_id + ',');
  144. if (auto_seen) {
  145. if (is_seen == -1) {
  146. list_seen = ',' + work_id + list_seen;
  147. is_seen = 1;
  148. }
  149. $('dl.work.meta.group').addClass('marked-seen');
  150. }
  151. else if (is_seen > -1) {
  152. $('dl.work.meta.group').addClass('marked-seen');
  153. }
  154. addSeenButtons();
  155. // if work id is on the kudosed list
  156. if (list_kudosed.indexOf(',' + work_id + ',') > -1) {
  157. $('dl.work.meta.group').addClass('has-kudos');
  158. }
  159. else {
  160. var found_kudos = false;
  161. // check if there are kudos from the user
  162. var user_kudos = $('#kudos').find('[href="/users/' + username + '"]');
  163. if (user_kudos.length) {
  164. // highlight blurb and add work id to kudosed list
  165. list_kudosed = ',' + work_id + list_kudosed;
  166. list_checked = list_checked.replace(',' + work_id + ',', ',');
  167. $('dl.work.meta.group').addClass('has-kudos');
  168. found_kudos = true;
  169. }
  170. else if (list_checked.indexOf(',' + work_id + ',') == -1) {
  171. // add work id to checked list
  172. list_checked = ',' + work_id + list_checked;
  173. }
  174. if (!found_kudos) {
  175. $('#new_kudo').click(function() {
  176. list_kudosed = localStorage.getItem('kudoshistory_kudosed');
  177. list_checked = localStorage.getItem('kudoshistory_checked');
  178. list_kudosed = ',' + work_id + list_kudosed;
  179. list_checked = list_checked.replace(',' + work_id + ',', ',');
  180. $('dl.work.meta.group').addClass('has-kudos');
  181. localStorage.setItem('kudoshistory_kudosed', list_kudosed);
  182. localStorage.setItem('kudoshistory_checked', list_checked);
  183. });
  184. }
  185. }
  186. // check if it's bookmarked
  187. var bookmark_button_text = $('a.bookmark_form_placement_open').filter(':first').text();
  188. if (bookmark_button_text.indexOf('Edit') > -1) {
  189. // highlight blurb
  190. list_bookmarked = ',' + work_id + list_bookmarked.replace(',' + work_id + ',', ',');
  191. $('dl.work.meta.group').addClass('is-bookmarked');
  192. }
  193. else {
  194. list_bookmarked = list_bookmarked.replace(',' + work_id + ',', ',');
  195. }
  196. }
  197. // keep the kudos, checked and bookmarked lists under 200k characters (~25k works)
  198. if (list_kudosed.length > 200000) {
  199. list_kudosed = list_kudosed.slice(0,180000);
  200. }
  201. if (list_checked.length > 200000) {
  202. list_checked = list_checked.slice(0,180000);
  203. }
  204. if (list_bookmarked.length > 200000) {
  205. list_bookmarked = list_bookmarked.slice(0,180000);
  206. }
  207. // keep the seen list under 2mil characters (~250k works)
  208. if (list_seen.length > 2000000) {
  209. list_seen = list_seen.slice(0,1900000);
  210. }
  211. // save all lists
  212. try {
  213. debug && console.log('god do i try (to save the lists)');
  214. localStorage.setItem('kudoshistory_kudosed', list_kudosed);
  215. localStorage.setItem('kudoshistory_checked', list_checked);
  216. localStorage.setItem('kudoshistory_seen', list_seen);
  217. localStorage.setItem('kudoshistory_bookmarked', list_bookmarked);
  218. }
  219. catch(e) {
  220. debug && console.log('error while saving lists');
  221. list_seen = list_seen.slice(0,list_seen.length*0.9);
  222. localStorage.setItem('kudoshistory_kudosed', list_kudosed);
  223. localStorage.setItem('kudoshistory_checked', list_checked);
  224. localStorage.setItem('kudoshistory_seen', list_seen);
  225. localStorage.setItem('kudoshistory_bookmarked', list_bookmarked);
  226. }
  227. }
  228. // check if work is on lists
  229. function blurbCheck(work_id, blurb_id, blurb, check_bookmark) {
  230. // if work id is on the kudosed list
  231. if (list_kudosed.indexOf(',' + work_id + ',') > -1) {
  232. debug && console.log('is kudosed');
  233. blurb.addClass('has-kudos');
  234. list_kudosed = ',' + work_id + list_kudosed.replace(',' + work_id + ',', ',');
  235. }
  236. // if work id is on the seen list
  237. else if (list_seen.indexOf(',' + work_id + ',') > -1) {
  238. debug && console.log('is seen');
  239. blurb.addClass('marked-seen');
  240. list_seen = ',' + work_id + list_seen.replace(',' + work_id + ',', ',');
  241. }
  242. // if work id is on the checked list
  243. else if (list_checked.indexOf(',' + work_id + ',') > -1) {
  244. debug && console.log('is checked');
  245. list_checked = ',' + work_id + list_checked.replace(',' + work_id + ',', ',');
  246. }
  247. else {
  248. debug && console.log('loading kudos for ' + blurb_id);
  249. // add a div to the blurb that will house the kudos
  250. blurb.append('<div id="kudos_' + blurb_id + '" style="display: none;"></div>');
  251. // retrieve a list of kudos from the work
  252. var work_url = 'http://archiveofourown.org/works/' + work_id + '/kudos #kudos';
  253. $('#kudos_' + blurb_id).load(work_url, function() {
  254. // check if there are kudos from the user
  255. var user_kudos = $('#kudos_' + blurb_id).find('[href="/users/' + username + '"]');
  256. if (user_kudos.length) {
  257. // highlight blurb and add work id to kudosed list
  258. $('#' + blurb_id).addClass('has-kudos');
  259. list_kudosed = ',' + work_id + list_kudosed;
  260. }
  261. else {
  262. // add work id to checked list
  263. list_checked = ',' + work_id + list_checked;
  264. }
  265. });
  266. }
  267. // if work id is on the bookmarked list
  268. if (check_bookmark) {
  269. if (list_bookmarked.indexOf(',' + work_id + ',') > -1) {
  270. debug && console.log('is bookmarked');
  271. blurb.addClass('is-bookmarked');
  272. list_bookmarked = ',' + work_id + list_bookmarked.replace(',' + work_id + ',', ',');
  273. }
  274. }
  275. }
  276. // mark all works on the page as seen
  277. function markPageSeen() {
  278. list_seen = localStorage.getItem('kudoshistory_seen');
  279. // for each work blurb
  280. $('li.work.blurb').not('.marked-seen').not('.has-kudos').not('.deleted').each(function() {
  281. var work_id = $(this).attr('id').replace('work_', '');
  282. debug && console.log('marking as seen ' + work_id);
  283. $(this).addClass('marked-seen');
  284. list_seen = ',' + work_id + list_seen;
  285. });
  286. // for each bookmark blurb
  287. $('li.bookmark.blurb').not('.marked-seen').not('.has-kudos').not('.deleted').each(function() {
  288. var work_link = $(this).find('h4 a:first').attr('href');
  289. // if it's not a series bookmark
  290. if (!!work_link && work_link.indexOf('series') == -1) {
  291. var work_id = work_link.split('/').pop();
  292. debug && console.log('marking as seen ' + work_id);
  293. $(this).addClass('marked-seen');
  294. list_seen = ',' + work_id + list_seen;
  295. }
  296. });
  297. localStorage.setItem('kudoshistory_seen', list_seen);
  298. }
  299. // mark all works on the page as unseen
  300. function markPageUnseen() {
  301. list_seen = localStorage.getItem('kudoshistory_seen');
  302. // for each work blurb
  303. $('li.work.blurb').not('.deleted').each(function() {
  304. var work_id = $(this).attr('id').replace('work_', '');
  305. debug && console.log('marking as unseen ' + work_id);
  306. $(this).removeClass('marked-seen');
  307. list_seen = list_seen.replace(',' + work_id + ',', ',');
  308. });
  309. // for each bookmark blurb
  310. $('li.bookmark.blurb').not('.deleted').each(function() {
  311. var work_link = $(this).find('h4 a:first').attr('href');
  312. // if it's not a series bookmark
  313. if (!!work_link && work_link.indexOf('series') == -1) {
  314. var work_id = work_link.split('/').pop();
  315. debug && console.log('marking as unseen ' + work_id);
  316. $(this).removeClass('marked-seen');
  317. list_seen = list_seen.replace(',' + work_id + ',', ',');
  318. }
  319. });
  320. localStorage.setItem('kudoshistory_seen', list_seen);
  321. }
  322. // re-check the page for kudos
  323. function recheckKudos() {
  324. list_kudosed = localStorage.getItem('kudoshistory_kudosed');
  325. list_checked = localStorage.getItem('kudoshistory_checked');
  326. // for each non-kudosed work blurb
  327. $('li.work.blurb').not('.has-kudos').not('.deleted').each(function() {
  328. // get work id
  329. var work_id = $(this).attr('id').replace('work_', '');
  330. debug && console.log('works loop ' + work_id);
  331. loadKudos(work_id, 'work_' + work_id, $(this));
  332. });
  333. // for each non-kudosed bookmark blurb
  334. $('li.bookmark.blurb').not('.has-kudos').not('.deleted').each(function() {
  335. // get bookmark and work ids
  336. var bookmark_id = $(this).attr('id');
  337. var work_link = $(this).find('h4 a:first').attr('href');
  338. // if it's not a series bookmark
  339. if (!!work_link && work_link.indexOf('series') == -1) {
  340. var work_id = work_link.split('/').pop();
  341. debug && console.log('bookmarks loop ' + work_id + ' ' + bookmark_id);
  342. loadKudos(work_id, bookmark_id, $(this));
  343. }
  344. });
  345. function loadKudos(work_id, blurb_id, blurb) {
  346. // add a div to the blurb that will house the kudos
  347. blurb.append('<div id="kudos_' + blurb_id + '" style="display: none;"></div>');
  348. // retrieve a list of kudos from the work
  349. var work_url = 'http://archiveofourown.org/works/' + work_id + '/kudos #kudos';
  350. $('#kudos_' + blurb_id).load(work_url, function() {
  351. // check if there are kudos from the user
  352. var user_kudos = $('#kudos_' + blurb_id).find('[href="/users/' + username + '"]');
  353. if (user_kudos.length) {
  354. // highlight blurb and add work id to kudosed list
  355. $('#' + blurb_id).addClass('has-kudos');
  356. list_kudosed = ',' + work_id + list_kudosed;
  357. list_checked = list_checked.replace(',' + work_id + ',', ',');
  358. }
  359. });
  360. }
  361. localStorage.setItem('kudoshistory_kudosed', list_kudosed);
  362. localStorage.setItem('kudoshistory_checked', list_checked);
  363. }
  364. // check the page for bookmarks
  365. function checkForBookmarks() {
  366. list_bookmarked = localStorage.getItem('kudoshistory_bookmarked');
  367. // for each work and bookmark blurb
  368. $('li.work.blurb').add('li.bookmark.blurb').not('.deleted').each(function() {
  369. // get work link
  370. var blurb_id = $(this).attr('id');
  371. var work_link = $(this).find('h4 a:first').attr('href');
  372. debug && console.log('checking for bookmark ' + blurb_id);
  373. // if it's not deleted and not a series
  374. if (!!work_link && work_link.indexOf('series') == -1) {
  375. var work_id = work_link.split('/').pop();
  376. // add a div to the blurb that will house the bookmark button
  377. $(this).append('<div id="bookmarked_' + blurb_id + '" style="display: none;"></div>');
  378. // retrieve the bookmark button from the work
  379. var work_url = 'http://archiveofourown.org' + work_link + ' a.bookmark_form_placement_open:first';
  380. $('#bookmarked_' + blurb_id).load(work_url, function() {
  381. // check if there is a bookmark from the user
  382. var bookmark_button_text = $('#bookmarked_' + blurb_id).find('a').text();
  383. if (bookmark_button_text.indexOf('Edit') > -1) {
  384. // highlight blurb
  385. $('#' + blurb_id).addClass('is-bookmarked');
  386. list_bookmarked = ',' + work_id + list_bookmarked.replace(',' + work_id + ',', ',');
  387. }
  388. else {
  389. $('#' + blurb_id).removeClass('is-bookmarked');
  390. list_bookmarked = list_bookmarked.replace(',' + work_id + ',', ',');
  391. }
  392. });
  393. }
  394. });
  395. localStorage.setItem('kudoshistory_bookmarked', list_bookmarked);
  396. }
  397. // show the box with import/export options
  398. function importExport() {
  399. var importexport_bg = $('<div id="importexport-bg"></div>');
  400. var importexport_box = $('<div id="importexport-box"></div>');
  401. var box_button_save = $('<input type="button" id="importexport-button-save" value="Import seen list"></input>');
  402. box_button_save.click(function() {
  403. var confirmed = confirm('Sure you want to replace your seen list?');
  404. if (confirmed) {
  405. var new_seen_list = $('#import-seen-list').val();
  406. if (new_seen_list.length > 2000000) {
  407. new_seen_list = new_seen_list.slice(0,1900000);
  408. }
  409. else if (new_seen_list == '') {
  410. new_seen_list = ',';
  411. }
  412. list_seen = new_seen_list;
  413. localStorage.setItem('kudoshistory_seen', new_seen_list);
  414. $('#importexport-save').prepend('Seen list imported! ');
  415. }
  416. });
  417. var box_button_close = $('<input type="button" id="importexport-button-close" value="Close"></input>');
  418. box_button_close.click(function() {
  419. importexport_box.detach();
  420. importexport_bg.detach();
  421. });
  422. importexport_box.append(
  423. $('<p class="actions"></p>').append(box_button_close),
  424. $('<h3></h3>').text('Export your seen list'),
  425. $('<p></p>').text('Copy your current seen list from the field below and save it wherever you want as a backup.'),
  426. $('<input type="text" id="export-seen-list" />').val(localStorage.getItem('kudoshistory_seen')),
  427. $('<h3 style="margin-top: 1.5em;"></h3>').text('Import your seen list'),
  428. $('<p></p>').html('Put your saved seen list in the field below and select the "Import seen list" button. <strong>Warning:</strong> it will <u>replace</u> your current seen list.'),
  429. $('<input type="text" id="import-seen-list" />'),
  430. $('<p class="actions" id="importexport-save"></p>').append(box_button_save)
  431. );
  432. $('body').append(importexport_bg, importexport_box);
  433. }
  434. // add the seen/unseen buttons
  435. function addSeenButtons() {
  436. var seen_button1 = $('<li class="mark-seen"></li>').html('<a>Seen &check;</a>');
  437. var seen_button2 = seen_button1.clone();
  438. $('ul.actions').on('click', 'li.mark-seen', function() {
  439. debug && console.log('seen_button clicked');
  440. list_seen = localStorage.getItem('kudoshistory_seen');
  441. list_seen = ',' + work_id + list_seen;
  442. localStorage.setItem('kudoshistory_seen', list_seen);
  443. $('dl.work.meta.group').addClass('marked-seen');
  444. seen_button1.replaceWith(unseen_button1);
  445. seen_button2.replaceWith(unseen_button2);
  446. });
  447. var unseen_button1 = $('<li class="mark-unseen"></li>').html('<a>Unseen &cross;</a>');
  448. var unseen_button2 = unseen_button1.clone();
  449. $('ul.actions').on('click', 'li.mark-unseen', function() {
  450. debug && console.log('unseen_button clicked');
  451. list_seen = localStorage.getItem('kudoshistory_seen');
  452. list_seen = list_seen.replace(',' + work_id + ',', ',');
  453. localStorage.setItem('kudoshistory_seen', list_seen);
  454. $('dl.work.meta.group').removeClass('marked-seen');
  455. unseen_button1.replaceWith(seen_button1);
  456. unseen_button2.replaceWith(seen_button2);
  457. });
  458. if (is_seen == -1) {
  459. $('li.bookmark').after(seen_button1);
  460. $('#new_kudo').parent().after(seen_button2);
  461. }
  462. else {
  463. $('li.bookmark').after(unseen_button1);
  464. $('#new_kudo').parent().after(unseen_button2);
  465. }
  466. }
  467. // attach the menu
  468. function addSeenMenu() {
  469. // get the header menu
  470. var header_menu = $('ul.primary.navigation.actions');
  471. // create and insert menu button
  472. var seen_menu = $('<li class="dropdown"></li>').html('<a>Seen works</a>');
  473. header_menu.find('li.search').before(seen_menu);
  474. // create and append dropdown menu
  475. var drop_menu = $('<ul class="menu dropdown-menu"></li>');
  476. seen_menu.append(drop_menu);
  477. // create button - import/export seen list
  478. var button_importexport_seen = $('<li></li>').html('<a>Import/export your seen list</a>');
  479. button_importexport_seen.click(function() {importExport();});
  480. // create button - all works
  481. var button_all_works = $('<li></li>').html('<a style="padding: 0.5em 0.5em 0.25em; text-align: center; font-weight: bold;">&mdash; For all works on this page: &mdash;</a>');
  482. // create button - mark page as seen
  483. var button_page_seen = $('<li></li>').html('<a>Mark as seen</a>');
  484. button_page_seen.click(function() {markPageSeen();});
  485. // create button - mark page as unseen
  486. var button_page_unseen = $('<li></li>').html('<a>Unmark as seen</a>');
  487. button_page_unseen.click(function() {markPageUnseen();});
  488. // create button - re-check page for kudos
  489. var button_recheck_kudos = $('<li></li>').html('<a>Re-check for kudos</a>');
  490. button_recheck_kudos.click(function() {recheckKudos();});
  491. // create button - check page for bookmarks
  492. var button_check_bookmarks = $('<li></li>').html('<a>Check for bookmarks</a>');
  493. button_check_bookmarks.click(function() {checkForBookmarks();});
  494. // create button - settings
  495. var button_settings = $('<li></li>').html('<a style="padding: 0.5em 0.5em 0.25em; text-align: center; font-weight: bold;">&mdash; Settings (click to change): &mdash;</a>');
  496. // create button - don't hide seen works
  497. var button_hide_no = $('<li class="hide-no"></li>').html('<a>Hide seen works: NO</a>');
  498. drop_menu.on('click', 'li.hide-no', function() {
  499. localStorage.setItem('kudoshistory_hide', 'yes');
  500. hide_seen = 1;
  501. addCss(1);
  502. button_hide_no.replaceWith(button_hide_yes);
  503. });
  504. // create button - hide seen works
  505. var button_hide_yes = $('<li class="hide-yes"></li>').html('<a>Hide seen works: YES</a>');
  506. drop_menu.on('click', 'li.hide-yes', function() {
  507. localStorage.setItem('kudoshistory_hide', 'collapse');
  508. hide_seen = 2;
  509. addCss(1);
  510. button_hide_yes.replaceWith(button_hide_collapse);
  511. });
  512. // create button - collapse seen works
  513. var button_hide_collapse = $('<li class="hide-collapse"></li>').html('<a>Hide seen works: COLLAPSE</a>');
  514. drop_menu.on('click', 'li.hide-collapse', function() {
  515. localStorage.setItem('kudoshistory_hide', 'no');
  516. hide_seen = 0;
  517. addCss(1);
  518. button_hide_collapse.replaceWith(button_hide_no);
  519. });
  520. // create button - hightlight bookmarked
  521. var button_bmarked_yes = $('<li class="bmarked-yes"></li>').html('<a>Highlight bookmarked: YES</a>');
  522. drop_menu.on('click', 'li.bmarked-yes', function() {
  523. localStorage.setItem('kudoshistory_highlight_bookmarked', 'no');
  524. highlight_bookmarked = false;
  525. addCss(2);
  526. button_bmarked_yes.replaceWith(button_bmarked_no);
  527. });
  528. // create button - don't hightlight bookmarked
  529. var button_bmarked_no = $('<li class="bmarked-no"></li>').html('<a>Highlight bookmarked: NO</a>');
  530. drop_menu.on('click', 'li.bmarked-no', function() {
  531. localStorage.setItem('kudoshistory_highlight_bookmarked', 'yes');
  532. highlight_bookmarked = true;
  533. addCss(2);
  534. button_bmarked_no.replaceWith(button_bmarked_yes);
  535. });
  536. // create button - mark as seen on open
  537. var button_auto_yes = $('<li class="auto-yes"></li>').html('<a>Mark as seen on open: YES</a>');
  538. drop_menu.on('click', 'li.auto-yes', function() {
  539. localStorage.setItem('kudoshistory_autoseen', 'no');
  540. auto_seen = false;
  541. button_auto_yes.replaceWith(button_auto_no);
  542. });
  543. // create button - don't mark as seen on open
  544. var button_auto_no = $('<li class="auto-no"></li>').html('<a>Mark as seen on open: NO</a>');
  545. drop_menu.on('click', 'li.auto-no', function() {
  546. localStorage.setItem('kudoshistory_autoseen', 'yes');
  547. auto_seen = true;
  548. button_auto_no.replaceWith(button_auto_yes);
  549. });
  550. // append buttons to the dropdown menu
  551. drop_menu.append(button_importexport_seen, button_all_works, button_page_seen, button_page_unseen, button_recheck_kudos, button_check_bookmarks, button_settings);
  552. switch (hide_seen) {
  553. case 1:
  554. drop_menu.append(button_hide_yes);
  555. break;
  556. case 2:
  557. drop_menu.append(button_hide_collapse);
  558. break;
  559. default:
  560. drop_menu.append(button_hide_no);
  561. }
  562. if (highlight_bookmarked) {
  563. drop_menu.append(button_bmarked_yes);
  564. }
  565. else {
  566. drop_menu.append(button_bmarked_no);
  567. }
  568. if (auto_seen) {
  569. drop_menu.append(button_auto_yes);
  570. }
  571. else {
  572. drop_menu.append(button_auto_no);
  573. }
  574. }
  575. // add a notice about an update
  576. function addNotice() {
  577. var update_1_5 = "<h3>version 1.5</h3>\
  578. <p><b>&bull; Import/export your seen list.</b> A whole new world of possibilities available from the menu! Save your list just in case your browser derps. Or take it with you to a different browser. Or just cuddle it gently at night.</p>";
  579. var update_1_4 = "<h3>version 1.4</h3>\
  580. <p><b>&bull; Thinner stripes on the highlighted blurbs.</b> You're not crazy, they changed a bit.</p>\
  581. <p><b>&bull; Remembers when you bookmark a work.</b> Page through your bookmarks list once to make it remember the works you bookmarked previously (shhh just do it). You can turn off the highlighting in the menu.</p>";
  582. var last_version = parseFloat(localStorage.getItem('kudoshistory_lastver'));
  583. if (isNaN(last_version)) {last_version = 0;}
  584. if (last_version < current_version) {
  585. var update_notice = $('<div id="kudoshistory-update" class="notice"></div>');
  586. update_notice.append("<h3><b>Kudosed and seen history updated!</b></h3>");
  587. update_notice.append(update_1_5);
  588. if (last_version < 1.4) {update_notice.append(update_1_4);}
  589. update_notice.append("<p><a id='kudoshistory-hide-update'>Don't show this again</a></p>");
  590. $('#main').prepend(update_notice);
  591. $('#kudoshistory-hide-update').click(function() {
  592. localStorage.setItem('kudoshistory_lastver', current_version);
  593. $('#kudoshistory-update').detach();
  594. });
  595. }
  596. }
  597. // add css rules to page head
  598. function addCss(option) {
  599. var css_highlight = '.has-kudos,\
  600. .has-kudos.marked-seen {background: url("http://i.imgur.com/jK7d4jh.png") left no-repeat, url("http://i.imgur.com/ESdBCSX.png") left repeat-y !important; padding-left: 50px !important;}\
  601. .marked-seen {background: url("http://i.imgur.com/ESdBCSX.png") left repeat-y !important; padding-left: 50px !important;}\
  602. dl.is-bookmarked {background: url("http://i.imgur.com/qol1mWZ.png") right repeat-y !important; padding-right: 50px !important;}\
  603. dl.has-kudos.is-bookmarked,\
  604. dl.has-kudos.marked-seen.is-bookmarked {background: url("http://i.imgur.com/jK7d4jh.png") left no-repeat, url("http://i.imgur.com/ESdBCSX.png") left repeat-y, url("http://i.imgur.com/qol1mWZ.png") right repeat-y !important;}\
  605. dl.marked-seen.is-bookmarked {background: url("http://i.imgur.com/ESdBCSX.png") left repeat-y, url("http://i.imgur.com/qol1mWZ.png") right repeat-y !important;}\
  606. #kudoshistory-update {padding: 0.5em 1em 1em 1em;}\
  607. #importexport-box {position: fixed; top: 0px; bottom: 0px; left: 0px; right: 0px; width: 60%; height: 80%; max-width: 800px; margin: auto; overflow-y: auto; border: 10px solid #eee; box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.2); padding: 0 20px; background-color: #ffffff; z-index: 999;}\
  608. #importexport-bg {position: fixed; width: 100%; height: 100%; background-color: #000000; opacity: 0.7; z-index: 998;}\
  609. #importexport-box input[type="button"] {height: auto;}\
  610. #importexport-box p.actions {float: none; text-align: right;}';
  611. var css_bookmarked = '.is-bookmarked {background: url("http://i.imgur.com/qol1mWZ.png") right repeat-y !important; padding-right: 50px !important;}\
  612. .has-kudos.is-bookmarked,\
  613. .has-kudos.marked-seen.is-bookmarked {background: url("http://i.imgur.com/jK7d4jh.png") left no-repeat, url("http://i.imgur.com/ESdBCSX.png") left repeat-y, url("http://i.imgur.com/qol1mWZ.png") right repeat-y !important;}\
  614. .marked-seen.is-bookmarked {background: url("http://i.imgur.com/ESdBCSX.png") left repeat-y, url("http://i.imgur.com/qol1mWZ.png") right repeat-y !important;}\
  615. .bookmark.is-bookmarked p.status {padding-right: 37px;}';
  616. var css_hide = '#main:not(.bookmarks-show) li.has-kudos,\
  617. #main:not(.bookmarks-show) li.marked-seen {display: none !important;}';
  618. var css_collapse = 'li.has-kudos h6.landmark.heading,\
  619. li.has-kudos > ul,\
  620. li.has-kudos blockquote.userstuff.summary,\
  621. li.has-kudos dl.stats,\
  622. li.has-kudos .header .fandoms.heading,\
  623. li.marked-seen h6.landmark.heading,\
  624. li.marked-seen > ul,\
  625. li.marked-seen blockquote.userstuff.summary,\
  626. li.marked-seen dl.stats,\
  627. li.marked-seen .header .fandoms.heading {display: none !important;}\
  628. li.has-kudos ul.required-tags,\
  629. li.marked-seen ul.required-tags {opacity: 0.6;}\
  630. li.has-kudos ul.required-tags li + li,\
  631. li.marked-seen ul.required-tags li + li {position: absolute; left: 56px; top: 0px;}\
  632. li.has-kudos ul.required-tags li + li + li,\
  633. li.marked-seen ul.required-tags li + li + li {left: 28px;}\
  634. li.has-kudos ul.required-tags li + li + li + li,\
  635. li.marked-seen ul.required-tags li + li + li + li {left: 84px; top: 0px;}\
  636. li.has-kudos .header,\
  637. li.marked-seen .header {min-height: 27px;}\
  638. li.has-kudos .header .heading,\
  639. li.marked-seen .header .heading {margin: 0.375em 5.25em 0px 121px;}';
  640. if (option == 0) {
  641. style.append(css_highlight);
  642. switch (hide_seen) {
  643. case 1:
  644. style.append(css_hide);
  645. break;
  646. case 2:
  647. style.append(css_collapse);
  648. }
  649. if (highlight_bookmarked) {
  650. style.append(css_bookmarked);
  651. }
  652. }
  653. else if (option == 1) {
  654. switch (hide_seen) {
  655. case 1:
  656. style.append(css_hide);
  657. break;
  658. case 2:
  659. style.html(style.html().replace(css_hide, ''));
  660. style.append(css_collapse);
  661. break;
  662. default:
  663. style.html(style.html().replace(css_collapse, ''));
  664. }
  665. }
  666. else if (option == 2) {
  667. if (highlight_bookmarked) {
  668. style.append(css_bookmarked);
  669. }
  670. else {
  671. style.html(style.html().replace(css_bookmarked, ''));
  672. }
  673. }
  674. }
  675. })(jQuery);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址