A Chrome extension that gives you finer control over MyAnimeList.net scores
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

66 linhas
2.2 KiB

  1. function patched_anime_checkScoreEnter(e, id) {
  2. if ((window.event ? window.event.keyCode : e.which) == 13)
  3. patched_anime_updateScore(id);
  4. else
  5. return true;
  6. }
  7. function patched_anime_updateScore(entry_id) {
  8. var new_score_centigrade = document.getElementById("scoretext" + entry_id).value;
  9. var new_score = Math.round(new_score_centigrade / 10.);
  10. var payload = {};
  11. $.post("/includes/ajax.inc.php?t=63", {id: entry_id, score: new_score}, function(data) {
  12. document.getElementById("scoreval" + entry_id).innerHTML = new_score_centigrade;
  13. document.getElementById("scoretext" + entry_id).value = "";
  14. document.getElementById("scorediv" + entry_id).style.display = "none";
  15. });
  16. payload[entry_id] = new_score_centigrade;
  17. chrome.storage.local.set(payload);
  18. }
  19. function list_hook() {
  20. // chrome.storage.local.get(null, function(items) { console.log(items); });
  21. // chrome.storage.local.clear();
  22. $("span[id^='scoreval']").each(function(i, el) {
  23. var aid = el.id.split("scoreval")[1];
  24. var oldscorediv = $("#scorediv" + aid);
  25. oldscorediv.attr("id", "delete-me");
  26. var newscorediv = $('<div id="scorediv' + aid + '" style="display: none;"><input type="text" id="scoretext' + aid + '" size="2"><input type="button" value="Go"></div>');
  27. newscorediv.insertAfter(oldscorediv);
  28. oldscorediv.remove();
  29. var input = $("#scoretext" + aid);
  30. var button = input.next();
  31. input.keydown(function(tid) {
  32. return function(e) {
  33. return patched_anime_checkScoreEnter(e, tid);
  34. }
  35. }(aid));
  36. button.click(function(tid) {
  37. return function() {
  38. return patched_anime_updateScore(tid);
  39. }
  40. }(aid));
  41. chrome.storage.local.get(aid, function(items) {
  42. if (aid in items) {
  43. $(el).text(items[aid]);
  44. }
  45. else {
  46. var cur = parseInt($(el).text());
  47. if (!isNaN(cur))
  48. $(el).text(cur * 10);
  49. }
  50. });
  51. });
  52. }
  53. $(document).ready(function() {
  54. if (window.location.href.indexOf("/animelist/") != -1) {
  55. list_hook();
  56. }
  57. });