Simkl inline tagging and memo taking

Adds inline-memos to Simkl for quick tagging

  1. // ==UserScript==
  2. // @name Simkl inline tagging and memo taking
  3. // @namespace http://dannywhittaker.com
  4. // @version 0.1
  5. // @description Adds inline-memos to Simkl for quick tagging
  6. // @author You
  7. // @match https://simkl.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. $(document).ready(function () {
  12. var userId, loaded = false, userData = {};
  13. function refreshData() {
  14. var animeUrl;
  15. userId = /\/(\d+)\//.exec($('#SimklHeaderMenuProfile').find('a').attr('href'))[1];
  16. if (userId) {
  17. animeUrl = '/' + userId + '/anime/';
  18. $.ajax({
  19. url: animeUrl
  20. }).done(function (obj) {
  21. var doc = $(obj), results, i, mapped = {};
  22. results = doc.find('.SimklTVMyTableTR').map(function () {
  23. return {
  24. id: /\/(\d+)\//.exec($(this).find('.SimklTVMyTableTRTitle a').attr('href'))[1],
  25. memo: $(this).find('.SimklTVMyTableTRMemo').text().replace(/\+ Add/, '')
  26. };
  27. });
  28. for (i = 0; i < results.length; i++) {
  29. mapped[results[i].id] = results[i];
  30. }
  31. userData = mapped;
  32. loaded = true
  33. });
  34. }
  35. }
  36. function refreshUi() {
  37. var currentAnimeId, userAnime, originalDiv, newObj;
  38. function setMemo() {
  39. var val = $(this).val();
  40. $.ajax({
  41. url: '/ajax/full/my_list.php',
  42. type: 'POST',
  43. data: {
  44. action: 'editTag',
  45. id: currentAnimeId,
  46. text: val
  47. }
  48. }).fail(function () {
  49. console.error(arguments);
  50. alert('Failed to save memo');
  51. });
  52. }
  53. if (loaded) {
  54. currentAnimeId = /\/anime\/(\d+)\//.exec(window.location.href)[1];
  55. if (currentAnimeId) {
  56. userAnime = userData[currentAnimeId];
  57. if (userAnime) {
  58. originalDiv = $('.SimklTVBtnBigAddToWatchListDiv').parent();
  59. if (originalDiv && originalDiv.length && !originalDiv.next('.js-zallist-inline-memo-wrap').length) {
  60. newObj = $('<textarea style="display: block; width: 100%; height: 80px; padding: 0; border: none; box-sizing: border-box; margin-top: 1em; background-color: rgba(255, 255, 255, 0.8); resize: vertical;" class="js-zallist-inline-memo-wrap"></textarea>');
  61. newObj.val(userAnime.memo);
  62. newObj.change(setMemo);
  63. newObj.insertAfter(originalDiv);
  64. }
  65. }
  66. }
  67. }
  68. }
  69. window.setInterval(refreshData, 60 * 1000);
  70. window.setInterval(refreshUi, 1 * 1000);
  71. refreshData();
  72. });