🏠 返回首頁 

Greasy Fork is available in English.

Lair Checker Adjusted 2.0 -- HTTPS+

Now with colours added by Alana!


安装此脚本?
  1. // ==UserScript==
  2. // @name Lair Checker Adjusted 2.0 -- HTTPS+
  3. // @description Now with colours added by Alana!
  4. // @author Tiff Zhang (derivative from bookmarklet at http://aywaslairchecker.mygamesonline.org/ ) -- with small modifications by Alana, #70812 on Aywas
  5. // @match https://www.aywas.com/*
  6. // @license MIT
  7. // @version 0.0.1.20240405182420
  8. // @namespace https://greasyfork.org/users/1284383
  9. // ==/UserScript==
  10. /* jshint -W097 */
  11. 'use strict';
  12. var alwaysHighlight = false;
  13. // Lair Checker script taken from http://aywaslairchecker.mygamesonline.org/
  14. function lair_check() {
  15. // <Species Name> <Genus Name> : <image url>
  16. var process = function() {
  17. var page = 1,
  18. petsTable = [],
  19. petImages = {},
  20. r###ltsTable = {},
  21. userID, version = "0.10",
  22. phoneHome = true,
  23. remoteVersion, versionCheckComplete = false,
  24. versionAnswer;
  25. function versionCheck() {
  26. $.ajax("http://aywaslairchecker.net/bookmarklets/lite/version.js", {
  27. dataType: "text",
  28. cache: false,
  29. error: function() {
  30. versionCheckComplete = true;
  31. },
  32. success: function(text) {
  33. var data = $.parseJSON(text);
  34. remoteVersion = data.currentVersionNew;
  35. if (remoteVersion !== version) {
  36. var ref = "http://aywaslairchecker.net/bookmarklets/lite/lite-";
  37. if (phoneHome) ref = ref + "checkin-";
  38. ref = ref + "min.bm.js";
  39. $.ajax(ref, {
  40. dataType: "text",
  41. cache: false,
  42. error: function() {
  43. versionCheckComplete = true;
  44. },
  45. success: function(text) {
  46. versionAnswer = $('<div></div>');
  47. versionAnswer.append($('<p class="keep">This version is out of date. The current version is V' + remoteVersion + '</p>'));
  48. versionAnswer.append($('<p class="keep">' + data.updateMessage + '</p>'));
  49. var a = $('<a href="' + text + '">Aywas Lair Checker V' + remoteVersion + '</a>');
  50. versionAnswer.append(a);
  51. versionCheckComplete = true;
  52. }
  53. });
  54. } else {
  55. versionCheckComplete = true;
  56. }
  57. }
  58. });
  59. }
  60. function generateOutput() {
  61. if (!versionCheckComplete) {
  62. window.setTimeout(generateOutput, 10000);
  63. return;
  64. }
  65. if (phoneHome) {
  66. $.get("http://aywaslairchecker.net/checkin.php", {
  67. id: userID,
  68. version: 0.6,
  69. lite: true
  70. });
  71. }
  72. var output = document.createElement('div'),
  73. k, ul, li, a, i;
  74. for (k in r###ltsTable) {
  75. if (r###ltsTable.hasOwnProperty(k)) {
  76. if (r###ltsTable[k].length > 1) {
  77. i = 0;
  78. ul = document.createElement('ul');
  79. $(ul).text(k);
  80. for (i = 0; i < r###ltsTable[k].length; i += 1) {
  81. li = document.createElement('li');
  82. a = document.createElement('a');
  83. $(a).text(r###ltsTable[k][i].name);
  84. $(a).attr("href", "https://www.aywas.com/pp/view/" + r###ltsTable[k][i].id + "/");
  85. $(li).append(a);
  86. $(ul).append(li);
  87. }
  88. }
  89. $(output).append(ul);
  90. }
  91. }
  92. $('title').text("Aywas Lair Checker - R###lts");
  93. if (versionAnswer) $('body').append(versionAnswer);
  94. $('body').append($(output));
  95. $('p:not(".keep")').hide().queue(function(next) {
  96. $(this).remove();
  97. next();
  98. });
  99. }
  100. function addTable(element) {
  101. var breed, id, name;
  102. breed = $(element).find(".gen-small > a > strong").text().split(' the ');
  103. breed = breed[breed.length - 1];
  104. breed = breed.trim().split('(')[0].trim().replace(/^\s*\S*(Male|Female|Androgynous|Hermaphrodite|Undecided|Robot|Genderless|Agender|Bigender|Genderqueer|Neutrois|Pangender|Genderfluid|Non-Binary|Intersex|Other)/i, "").trim();
  105. id = $(element).find(".gen-small > a > strong").text().split('(')[1].match(/\d+/ig);
  106. if (id) {
  107. id = Number(id[0]);
  108. }
  109. name = $(element).find(".gen-small > a > strong").text();
  110. if (!breed.match(/Custom/ig)) {
  111. if (!r###ltsTable[breed]) {
  112. r###ltsTable[breed] = [];
  113. }
  114. r###ltsTable[breed].push({
  115. id: id,
  116. name: name
  117. });
  118. }
  119. }
  120. function addTables() {
  121. var i;
  122. for (i = 0; i < petsTable.length; i += 1) {
  123. addTable(petsTable[i]);
  124. }
  125. localStorage.setItem("petImages", JSON.stringify(petImages));
  126. localStorage.setItem("petsList", JSON.stringify(r###ltsTable));
  127. generateOutput();
  128. }
  129. function fetchPage() {
  130. $('body').append($("<p>Loading page " + page + ". Pets loaded so far: " + petsTable.length + "</p>"));
  131. $('title').text("Aywas Lair Checker: Loading page " + page + ". Pets loaded so far: " + petsTable.length);
  132. var listUrl = "https://www.aywas.com/lair/group/" + userID + "/all/?p=" + page + "&l=240",
  133. pageR###lt = [],
  134. i;
  135. $.ajax(listUrl, {
  136. dataType: "text",
  137. success: function(xml) {
  138. //xml = xml.replace(/<[^\/]*img[^>]*>([^<]*<[^\/\w]*\/img[^>]*>)*/gi, "");
  139. pageR###lt = $(xml).find('div#lair-sort-pets > div');
  140. for (i = 0; i < pageR###lt.length; i += 1) {
  141. pageR###lt[i].innerHTML = pageR###lt[i].innerHTML.replace(/src\s*=\s*"https:\/\/www\.aywas\.com\/+images(\/+images)?\/pets\/([^"]+)"/gi, function (match, $i, identifier) {
  142. if (petImages[identifier]) {
  143. petImages[identifier]++;
  144. } else {
  145. petImages[identifier] = 1;
  146. }
  147. return "";
  148. });
  149. petsTable.push(pageR###lt[i]);
  150. }
  151. page = page + 1;
  152. if (pageR###lt.length) {
  153. //If your lair checker gets stuck and won't continue, increase the number below by 1000 and try again until it makes it all the way through!
  154. setTimeout(fetchPage,1000);
  155. } else {
  156. $('body').append($("<p>Load complete. Loaded " + petsTable.length + " pets.</p>"));
  157. addTables();
  158. }
  159. }
  160. });
  161. }
  162. function getUserID() {
  163. userID = $("div#side > h3 > a");
  164. if (userID && userID.length) {
  165. userID = Number(userID.attr('href').match(/\d+/i)[0]);
  166. }
  167. }
  168. var scripts = document.getElementsByTagName('script');
  169. while (scripts.length) {
  170. scripts[0].parentElement.removeChild(scripts[0]);
  171. }
  172. scripts = document.getElementsByTagName('link');
  173. while (scripts.length) {
  174. scripts[0].parentElement.removeChild(scripts[0]);
  175. }
  176. var script = document.createElement('script');
  177. script.src = "//code.jquery.com/jquery-1.10.2.min.js";
  178. script.type = "text/javascript";
  179. script.onload = function() {
  180. getUserID();
  181. $('body').remove();
  182. $('html').append($('<body></body>'));
  183. $('body').append($('<h1>Aywas Lair Checker V' + version + '</h1>'));
  184. window.setTimeout(versionCheck, 1);
  185. fetchPage();
  186. };
  187. document.getElementsByTagName('head')[0].appendChild(script);
  188. };
  189. if (!(location.host.match(/.*aywas.*/ig) && location.host.match(/.*aywas.*/ig).length) && !(location.hostname.match(/.*aywas.*/ig) && location.hostname.match(/.*aywas.*/ig).length)) {
  190. alert("Please re-run this bookmarklet from Aywas.com!");
  191. location.href = "https://www.aywas.com/";
  192. } else {
  193. process();
  194. }
  195. };
  196. $(document).ready(function() {
  197. var map = [];
  198. $("#side-mail").prepend('<p><a href="javascript:;" id="owned-pets-button" class="ctabtn normal"><span>Owned Pets</span></a></p>');
  199. $("#side-mail").prepend('<p><a href="#" id="lair-check-button" class="ctabtn normal"><span>Check Lair</span></a></p>');
  200. $("#lair-check-button").click(function() {
  201. lair_check();
  202. });
  203. function highlightPets() {
  204. var petsList = JSON.parse(localStorage.getItem("petsList"));
  205. var petImages = JSON.parse(localStorage.getItem("petImages"));
  206. var imageRegex = /https?:\/\/www\.aywas\.com\/+images(\/+images)?\/pets\/([^"]+)/i;
  207. $("#content img").each(function () {
  208. var res = $(this).attr('src').match(imageRegex);
  209. if (res) {
  210. var ident = res[2];
  211. if (petImages[ident]) {
  212. if (petImages[ident] > 1) {
  213. $(this).css("background-color", "blue");
  214. } else {
  215. $(this).css("background-color", "green");
  216. }
  217. } else {
  218. $(this).css("background-color", "red");
  219. }
  220. }
  221. });
  222. $("#lair-pets .item-thumb").each(function () {
  223. const nameElement = $(this).find(".gen-small > a > strong");
  224. const name = nameElement.text();
  225. let breed = name.split(' the ');
  226. breed = breed[breed.length - 1];
  227. breed = breed.trim().split('(')[0].trim().replace(/^\s*\S*(Male|Female|Androgynous|Hermaphrodite|Undecided|Robot|Genderless|Agender|Bigender|Genderqueer|Neutrois|Pangender|Genderfluid|Non-Binary|Intersex|Other)/i, "").trim();
  228. let id = name.split('(')[1].match(/\d+/ig);
  229. if (id) {
  230. id = Number(id[0]);
  231. }
  232. let list = petsList[breed];
  233. if (list) {
  234. list.forEach(function (pet, i) {
  235. if (pet.id === id && i >= 1) {
  236. nameElement.css("background-color", "purple");
  237. }
  238. });
  239. }
  240. });
  241. $("select").each(function () {
  242. if ($(this).attr("name") == "species_id") {
  243. $(this).find("option").each(function () {
  244. var pet = $(this).html();
  245. if (r###ltsTable[pet]) {
  246. $(this).html(pet + " (OWNED)");
  247. }
  248. });
  249. }
  250. });
  251. }
  252. $("#owned-pets-button").click(highlightPets);
  253. // From http://stackoverflow.com/questions/5203407/javascript-multiple-keys-pressed-at-once
  254. onkeydown = onkeyup = function(e){
  255. e = e || event; // to deal with IE
  256. map[e.keyCode] = e.type == 'keydown';
  257. if (map[17] && map[81]) {
  258. highlightPets();
  259. }
  260. }
  261. if (alwaysHighlight) {
  262. highlightPets();
  263. }
  264. });