ExResurrect

Resurrect E/Ex gallery listings

目前為 2021-10-16 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name ExResurrect
  3. // @namespace https://sleazyfork.org/en/users/285675-hauffen
  4. // @version 1.21.10
  5. // @description Resurrect E/Ex gallery listings
  6. // @author Hauffen
  7. // @runat document-start
  8. // @require https://code.jquery.com/jquery-3.3.1.min.js
  9. // @include /https?:\/\/(e-|ex)hentai\.org\/.*/
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. let $ = window.jQuery;
  14. var spl = document.URL.split('/');
  15. var dead, claim, language, translated;
  16. const category = {doujinshi: 'ct2', manga: 'ct3', artistcg: 'ct4', gamecg: 'ct5', western: 'cta', nonh: 'ct9', imageset: 'ct6', cosplay: 'ct7', asianporn: 'ct8', misc: 'ct1'};
  17. const fileSizeLabels = [ "B", "KB", "MB", "GB" ];
  18. const defaultNamespace = "misc";
  19. const tags = {};
  20.  
  21. function gotonext() {};
  22. // Override the default function to prevent redirect
  23.  
  24. addJS_Node (gotonext); // Inject the override function before doing anything to avoid the timeout redirect
  25.  
  26. function addJS_Node(text, s_URL, funcToRun, runOnLoad) {
  27. var scriptNode = document.createElement('script');
  28. if (runOnLoad) {
  29. scriptNode.addEventListener("load", runOnLoad, false);
  30. }
  31. scriptNode.type = "text/javascript";
  32. if (text) scriptNode.textContent = text;
  33. if (s_URL) scriptNode.src = s_URL;
  34. if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
  35.  
  36. var targ = document.getElementsByTagName('head')[0] || document.body || document.documentElement;
  37. targ.appendChild(scriptNode);
  38. }
  39. // There's a better critera for this probably
  40. if ($('.d').length && !spl[3].match('upload')) {
  41. dead = true;
  42. if ($('.d').text().indexOf("copyright") > 0) claim = $('.d').text().split('by')[1].split('.')[0].trim();
  43. $('.d').remove(); // Leave us with an entirely blank page to build up
  44. }
  45. generateRequest();
  46.  
  47. /**
  48. * Generate the JSON request for the E-H API
  49. */
  50. function generateRequest() {
  51. var reqList = [[spl[4], spl[5]]]; // We use an array for our gidlist, since the API can handle up to 25 galleries per request
  52. var request = {"method": "gdata", "gidlist": reqList, "namespace": 1};
  53.  
  54. var req = new XMLHttpRequest();
  55. req.onreadystatechange = e => {
  56. if (req.readyState == 4) {
  57. if (req.status == 200) {
  58. var apirsp = JSON.parse(req.responseText);
  59. for (var i = 0; i < apirsp.gmetadata.length; i++) {
  60. if (dead) generateListing(apirsp.gmetadata[i]);
  61. else generateLiveListing(apirsp.gmetadata[i]);
  62. }
  63. } else {
  64. console.error();
  65. }
  66. }
  67. }
  68. req.open("POST", document.location.origin + "/api.php", true); // Due to CORS, we need to use the API on the same domain as the script
  69. req.send(JSON.stringify(request));
  70. }
  71.  
  72. function generateListing(glisting) {
  73. var d = new Date(glisting.posted * 1000);
  74. document.title = glisting.title;
  75. generateTags(glisting);
  76. // There's a better way to do this, but I suck
  77. var listing = $(`
  78. <div id="nb" class="nose1">
  79. <div><a href="` + document.location.origin + `">Front<span class="nbw1"> Page</span></a></div>
  80. <div><a href="` + document.location.origin + `/watched">Watched</a></div>
  81. <div><a href="` + document.location.origin + `/popular">Popular</a></div>
  82. <div><a href="` + document.location.origin + `/torrents.php">Torrents</a></div>
  83. <div><a href="` + document.location.origin + `/favorites.php">Fav<span class="nbw1">orite</span>s</a></div>
  84. <div><a href="` + document.location.origin + `/uconfig.php">Settings</a></div>
  85. <div><a href="` + document.location.origin + `/upload/manage.php"><span class="nbw2">My </span>Uploads</a></div>
  86. <div><a href="` + document.location.origin + `/mytags">My Tags</a></div>
  87. </div>
  88. <div class="gm">
  89. <div id="gleft">
  90. <div id="gd1">
  91. <div style="width:250px; height:354px; background:transparent url(` + glisting.thumb.substring(0, glisting.thumb.length-5) + `250.jpg) 0 0 no-repeat"></div>
  92. </div>
  93. </div>
  94. <div id="gd2">
  95. <h1 id="gn">` + glisting.title + `</h1>
  96. <h1 id="gj">` + glisting.title_jpn + `</h1>
  97. </div>
  98. <div id="gmid">
  99. <div id="gd3">
  100. <div id="gdc">
  101. <div class="cs ` + category[glisting.category.toLowerCase().replace(/ /g, '').replace(/-/g, '')] + `" onclick="document.location='` + document.location.origin + '/' + glisting.category.toLowerCase().replace(/ /g, '') + `'">` + glisting.category + `</div>
  102. </div>
  103. <div id="gdn">
  104. <a href="` + document.location.origin + '/uploader/' + glisting.uploader + '">' + glisting.uploader + `</a>
  105. </div>
  106. <div id="gdd">
  107. <table>
  108. <tbody>
  109. <tr><td class="gdt1">Posted:</td><td class="gdt2">` + d.getUTCFullYear().toString() + '-' + (d.getUTCMonth() + 1).toString().padStart(2, '0') + '-' + d.getUTCDate().toString().padStart(2, '0') + ' ' + d.getUTCHours().toString().padStart(2, '0') + ':' + d.getUTCMinutes().toString().padStart(2, '0') + `</td></tr>
  110. <tr><td class="gdt1">Visible:</td><td class="gdt2">` + (glisting.expunged ? 'No' : 'Yes') + `</td></tr>
  111. <tr><td class="gdt1">Language:</td><td class="gdt2">` + (translated ? language + `&nbsp <span class="halp" title="This gallery has been translated from the original language text.">TR</span>` : language) + `</td></tr>
  112. <tr><td class="gdt1">File Size:</td><td class="gdt2">` + getPrettyFileSize(glisting.filesize) + `</td></tr>
  113. <tr><td class="gdt1">Length:</td><td class="gdt2">` + glisting.filecount + ` pages</td></tr>
  114. <tr><td class="gdt1">Removal:</td><td class="gdt2">` + claim + `</td></tr>
  115. </tbody>
  116. </table>
  117. </div>
  118. <div id="gdr">
  119. <table>
  120. <tbody>
  121. <tr>
  122. <td class="grt1">Rating:</td>
  123. <td class="grt2">
  124. <div id="rating_image" class="ir" style="background-position:` + getStarNumber(glisting.rating, true) + `"></div>
  125. </td>
  126. </tr>
  127. <tr><td id="rating_label" colspan="2">Average: ` + glisting.rating + `</td></tr>
  128. </tbody>
  129. </table>
  130. </div>
  131. <div id="gdf">
  132. <div style="float:left; cursor:pointer;" id="fav"></div>
  133. &nbsp;
  134. <a id="favoritelink" href="#" onclick="window.open('` + document.location.origin + '/gallerypopups.php?gid=' + glisting.gid + '&t=' + glisting.token + `&act=addfav','Add to Favorites','width=675,height=415')">
  135. <img src="` + (window.location.hostname.indexOf("exhentai") >= 0 ? "https://exhentai.org/img/mr.gif" : "https://ehgt.org/g/mr.gif") + `" />
  136. Add to Favorites
  137. </a>
  138. </div>
  139. </div>
  140. <div id="gd4">
  141. <div id="taglist">
  142. </div>
  143. </div>
  144. <div id="gd5">
  145. <p class="g3 gsp">
  146. <img src="` + (window.location.hostname.indexOf("exhentai") >= 0 ? "https://exhentai.org/img/mr.gif" : "https://ehgt.org/g/mr.gif") + `" />
  147. <a href="">Gallery Unavailable</a>
  148. </p>
  149. <p class="g2 gsp">
  150. <img src="` + (window.location.hostname.indexOf("exhentai") >= 0 ? "https://exhentai.org/img/mr.gif" : "https://ehgt.org/g/mr.gif") + `" />
  151. <a id="dl_eze" href="#">EZE JSON</a>
  152. </p>
  153. <p class="g2">
  154. <img src="` + (window.location.hostname.indexOf("exhentai") >= 0 ? "https://exhentai.org/img/mr.gif" : "https://ehgt.org/g/mr.gif") + `" />
  155. <a id="dl_ehdl">E-HDL JSON</a>
  156. </p>
  157. <p class="g2">
  158. <img src="` + (window.location.hostname.indexOf("exhentai") >= 0 ? "https://exhentai.org/img/mr.gif" : "https://ehgt.org/g/mr.gif") + `" />
  159. <a id="dl_gdl">Gallery-DL JSON</a>
  160. </p>
  161. </div>
  162. <div class="c"></div>
  163. </div>
  164. <div class="c"></div>
  165. </div>
  166. `);
  167. $('body').append(listing);
  168. // Generate taglist table
  169. var taglist = "<table><tbody>";
  170. for (const namespace in tags) {
  171. taglist += `<tr><td class="tc">${namespace}:</td><td>`;
  172. for (var i = 0; i < tags[namespace].length; i++) {
  173. taglist += `<div id="td_${namespace}:${tags[namespace][i]}" class="gt" style="opacity:1.0"><a id="ta_${namespace}:${tags[namespace][i]}" href="${document.location.origin}/tag/${namespace}:${tags[namespace][i]}">${tags[namespace][i]}</a></div>`;
  174. }
  175. taglist += "</td></tr>";
  176. }
  177. taglist += "</tbody></table>";
  178. $('#taglist').append(taglist);
  179. // I want to make these smaller, but the 'this' call prevents me from doing so
  180. $('#dl_eze').on('click', function() {
  181. var json = JSON.stringify(toEze(glisting), null, " "),
  182. blob = new Blob([json], {type: "octet/stream"}),
  183. url = window.URL.createObjectURL(blob);
  184. this.href = url;
  185. this.target = '_blank';
  186. this.download = 'info.json';
  187. });
  188. $('#dl_ehdl').on('click', function() {
  189. var blob = new Blob([toEhDl(glisting)], {type: "text/plain"}),
  190. url = window.URL.createObjectURL(blob);
  191. this.href = url;
  192. this.target = '_blank';
  193. this.download = 'info.json';
  194. });
  195. $('#dl_gdl').on('click', function() {
  196. var json = JSON.stringify(toGalleryDl(glisting), null, " "),
  197. blob = new Blob([json], {type: "octet/stream"}),
  198. url = window.URL.createObjectURL(blob);
  199. this.href = url;
  200. this.target = '_blank';
  201. this.download = 'info.json';
  202. });
  203. // Try to generate torrent links
  204. if (glisting.torrentcount > 0) {
  205. $(`<div id="torrents" style="border-top:1px solid #000; padding: 10px 10px 5px 10px;"><p><span class="halp" title="If the torrent link doesn't work, try the magnet link">Possible Torrents:</span></p></div>`).appendTo('.gm');
  206. for (var j = 0; j < glisting.torrentcount; j++) {
  207. $(`<div><img src="` + (window.location.hostname.indexOf("exhentai") >= 0 ? "https://exhentai.org/img/mr.gif" : "https://ehgt.org/g/mr.gif") + `" /><a style="padding-left:3px;margin-right:1.5px;" href="` + generateTorrentLink(glisting, j) + `">` + glisting.torrents[j].name + `</a>&#9;` + getPrettyFileSize(glisting.torrents[j].fsize) + `<span style="float:right">Added ` + getTimestampDateString(glisting.torrents[j].added * 1000) + `</span><p style="margin-left:8px"><a href=" magnet:?xt=urn:btih:` + glisting.torrents[j].hash + `">Magnet Link</a></p>`).appendTo('#torrents');
  208. }
  209. }
  210. generateSearchLink(glisting);
  211. }
  212.  
  213. function generateLiveListing(glisting) {
  214. generateTags(glisting);
  215. var listing = $(`
  216. <p class="g2">
  217. <img src="` + (window.location.hostname.indexOf("exhentai") >= 0 ? "https://exhentai.org/img/mr.gif" : "https://ehgt.org/g/mr.gif") + `" />
  218. <a id="dl_eze" href="#">EZE</a> / <a id="dl_ehdl" href="#">E-HDL</a> / <a id="dl_gdl" href="#">G-DL</a>
  219. </p>`);
  220. $('#gd5').append(listing);
  221. $('#gmid').css('height', 'unset');
  222. $('#dl_eze').on('click', function() {
  223. var json = JSON.stringify(toEze(glisting), null, " "),
  224. blob = new Blob([json], {type: "octet/stream"}),
  225. url = window.URL.createObjectURL(blob);
  226. this.href = url;
  227. this.target = '_blank';
  228. this.download = 'info.json';
  229. });
  230. $('#dl_ehdl').on('click', function() {
  231. var blob = new Blob([toEhDl(glisting)], {type: "text/plain"}),
  232. url = window.URL.createObjectURL(blob);
  233. this.href = url;
  234. this.target = '_blank';
  235. this.download = 'info.json';
  236. });
  237. $('#dl_gdl').on('click', function() {
  238. var json = JSON.stringify(toGalleryDl(glisting), null, " "),
  239. blob = new Blob([json], {type: "octet/stream"}),
  240. url = window.URL.createObjectURL(blob);
  241. this.href = url;
  242. this.target = '_blank';
  243. this.download = 'info.json';
  244. });
  245. generateSearchLink(glisting);
  246. }
  247.  
  248. function generateSearchLink(glisting) {
  249. var menu = $(`
  250. <div id="menu">
  251. <button class="menuControl">Custom Search</button>
  252. <div class="menuContent">
  253. <a href='/?f_cats=0&f_sname=1&f_search="` + encodeURIComponent(getShortTitle(glisting.title)) + `"' rel="noreferrer" target="_blank">Search by Name</a>
  254. <a href='/?f_cats=0&f_sname=1&f_search="` + encodeURIComponent(glisting.title) + `"' rel="noreferrer" target="_blank">Search by Full Name</a>
  255. <a href='https://nhentai.net/search/?q="` + encodeURIComponent(getShortTitle(glisting.title)) + `"' rel="noreferrer" target="_blank">Search by Name (nhentai.net)</a>
  256. <a href='https://nhentai.net/search/?q="` + encodeURIComponent(glisting.title) + `"' rel="noreferrer" target="_blank">Search by Full Name (nhentai.net</a>
  257. <a href="https://hitomi.la/search.html?` + encodeURIComponent(getShortTitle(glisting.title)) + `" rel="noreferrer" target="_blank">Search by Name (hitomi.la)</a>
  258. <a href="https://panda.chaika.moe/search/?qsearch=` + encodeURIComponent(getShortTitle(glisting.title)) + `" rel="noreferrer" target="_blank">Search by Name (chaika)</a>
  259. <a href="https://panda.chaika.moe/search/?qsearch=` + encodeURIComponent(glisting.title) + `" rel="noreferrer" target="_blank">Search by Full Name (chaika)</a>
  260. <a href="https://panda.chaika.moe/search/?qsearch=` + encodeURIComponent(getGalleryUrl(glisting)) + `" rel="noreferrer" target="_blank">Search by URL (chaika)</a>
  261. </div>
  262. </div>`);
  263. $('.gm').append(menu);
  264. $(document).click(e => {
  265. if (e.target.className != 'menuControl') {
  266. $('div.menuContent').css("display", "none");
  267. }
  268. });
  269. $('.menuControl').click(e => {
  270. $('div.menuContent').css("display", "flex");
  271. });
  272. }
  273.  
  274. function generateTorrentLink(glisting, index) {
  275. if (window.location.hostname.indexOf("exhentai") > 0) return window.location.origin + "/torrent/" + glisting.gid + "/" + glisting.torrents[index].hash + ".torrent";
  276. else return "https://ehtracker.org/get/" + glisting.gid + "/" + glisting.torrents[index].hash + ".torrent";
  277. }
  278.  
  279. function generateTags(glisting) {
  280. if (Array.isArray(glisting.tags)) {
  281. for (const jsonTag of glisting.tags) {
  282. const stringTag = getJsonString(jsonTag);
  283. if (stringTag === null) { continue; }
  284.  
  285. const {tag, namespace} = getTagAndNamespace(stringTag);
  286.  
  287. let namespaceTags;
  288. if (tags.hasOwnProperty(namespace)) {
  289. namespaceTags = tags[namespace];
  290. } else {
  291. namespaceTags = [];
  292. tags[namespace] = namespaceTags;
  293. }
  294.  
  295. namespaceTags.push(tag);
  296. }
  297. }
  298.  
  299. // Tag-based info
  300. if (tags.hasOwnProperty("language")) {
  301. const languageTags = tags.language;
  302. const translatedIndex = languageTags.indexOf("translated");
  303. translated = (translatedIndex >= 0);
  304. if (translatedIndex !== 0) {
  305. language = toProperCase(languageTags[0]);
  306. }
  307. } else {
  308. language = "Japanese";
  309. translated = false;
  310. }
  311. }
  312.  
  313. function toEhDl(info) { // EH-DL
  314. var d = new Date(info.posted * 1000);
  315. var d2 = new Date();
  316. var output = info.title + "\r\n" + info.title_jpn + "\r\n" + document.URL + "\r\n\r\nCategory: " + info.category + "\r\nUploader: " + info.uploader + "\r\nPosted: " + d.getUTCFullYear().toString() + '-' + (d.getUTCMonth() + 1).toString().padStart(2, '0') + '-' + d.getUTCDate().toString().padStart(2, '0') + ' ' + d.getUTCHours().toString().padStart(2, '0') + ':' + d.getUTCMinutes().toString().padStart(2, '0') +
  317. "\r\nParent: " + (spl[3] == 'g' ? $('.gdt2 > a').text() : "None" ) + "\r\nVisible: " + (info.expunged ? 'No' : 'Yes') + "\r\nLanguage: " + language + "\r\nFile Size: " + getPrettyFileSize(info.filesize) + "\r\nLength: " + info.filecount + " pages\r\nFavorited: " + (spl[3] == 'g' ? $('#rating_count').text() : "Null" ) + "\r\nRating: " + info.rating + "\r\n\r\nTags:\r\n";
  318. for (const namespace in tags) {
  319. output += `> ${namespace}: `;
  320. for (var i = 0; i < tags[namespace].length; i++) {
  321. output += `${tags[namespace][i]}`;
  322. if (i < tags[namespace].length - 1) output += ", ";
  323. }
  324. output += "\r\n";
  325. }
  326. output += `\r\n\r\n\r\nDownloaded on ${d2.toUTCString()}`;
  327. return output;
  328. }
  329.  
  330. function toEze(info) { // EZE
  331. const date = new Date(toNumberOrDefault(info.posted * 1000, 0));
  332. return {
  333. gallery_info: {
  334. title: toStringOrDefault(info.title, ""),
  335. title_original: toStringOrDefault(info.title_jpn, ""),
  336. uploader: toStringOrDefault(info.uploader, ""),
  337.  
  338. category: toStringOrDefault(info.category, ""),
  339. tags: tagsToCommonJson(tags),
  340.  
  341. language: toStringOrDefault(language, ""),
  342. translated: !!translated,
  343.  
  344. upload_date: [
  345. date.getUTCFullYear(),
  346. date.getUTCMonth() + 1,
  347. date.getUTCDate(),
  348. date.getUTCHours(),
  349. date.getUTCMinutes(),
  350. date.getUTCSeconds()
  351. ],
  352.  
  353. source: {
  354. site: toStringOrDefault(document.location.host.substr(0, document.location.host.length - 4), ""),
  355. gid: (info.identifier !== null ? toNumberOrDefault(info.gid, 0) : 0),
  356. token: (info.identifier !== null ? toStringOrDefault(info.token, 0) : 0),
  357. parent_gallery: toParentOrDefault(),
  358. newer_version: []
  359. }
  360. }
  361. };
  362. }
  363.  
  364. function toGalleryDl(info) { // Gallery-DL
  365. const date = new Date(toNumberOrDefault(info.posted * 1000, 0));
  366. return {
  367. category: toStringOrDefault(document.location.host.substr(0, document.location.host.length - 4), ""),
  368. cost: null,
  369. count: info.filecount,
  370. date: toStringOrDefault(getTimestampDateString(date), ""),
  371. extension: null,
  372. filename: null,
  373. gallery_id: toNumberOrDefault(info.gid, 0),
  374. gallery_size: toNumberOrDefault(info.filesize, 0),
  375. gallery_token: toStringOrDefault(info.token, 0),
  376. height: null,
  377. image_token: null,
  378. lang: null,
  379. language: toStringOrDefault(language, ""),
  380. num: 1,
  381. parent: toParentOrDefault(),
  382. size: toNumberOrDefault(info.filesize, 0),
  383. subcategory: 'gallery',
  384. tags: info.tags,
  385. title: toStringOrDefault(info.title, ""),
  386. title_jp: toStringOrDefault(info.title_jpn, ""),
  387. uploader: toStringOrDefault(info.uploader, ""),
  388. visible: info.expunged ? 'No' : 'Yes',
  389. width: null
  390. };
  391. }
  392.  
  393. /**
  394. * Convert the star count of a specified element to a double
  395. * @param {Object} el - A specific element within the DOM, or a double
  396. * @param {Boolean} transpose - Whether we're converting background position to double, or double to background position
  397. */
  398. function getStarNumber(el, transpose) {
  399. var starCount = {5: '0px -1px', 4.5: '0px -21px', 4: '-16px -1px', 3.5: '-16px -21px', 3: '-32px -1px', 2.5: '-32px -21px', 2: '-48px -1px', 1.5: '-48px -21px', 1: '-64px -1px', 0.5: '-64px -21px'};
  400. if (!transpose) {
  401. var stars = $(el).find('.ir').css('background-position');
  402. return Object.keys(starCount).find(key => starCount[key] === stars);
  403. } else return starCount[(Math.round(el * 2) / 2).toFixed(1)]; // Ratings are given in x.xx numbers, but we need either whole integers, or half integers
  404. }
  405.  
  406. /** ------ Helper functions cannibalized from the dnsev's script ------ */
  407. function getTagAndNamespace(tag) {
  408. const pattern = /^(?:([^:]*):)?([\w\W]*)$/;
  409. const match = pattern.exec(tag);
  410. return (match !== null) ?
  411. ({ tag: match[2], namespace: match[1] || defaultNamespace }) :
  412. ({ tag: tag, namespace: defaultNamespace });
  413. }
  414.  
  415. function getJsonString(value) {
  416. if (typeof(value) === "string") { return value; }
  417. if (typeof(value) === "undefined" || value === null) { return value; }
  418. return `${value}`;
  419. }
  420.  
  421. function toProperCase(text) {
  422. return text.replace(/(^|\W)(\w)/g, (m0, m1, m2) => `${m1}${m2.toUpperCase()}`);
  423. }
  424.  
  425. function getPrettyFileSize(bytes) {
  426. const ii = fileSizeLabels.length - 1;
  427. let i = 0;
  428. while (i < ii && bytes >= 1024) {
  429. bytes /= 1024;
  430. ++i;
  431. }
  432. return `${bytes.toFixed(i === 0 ? 0 : 2)} ${fileSizeLabels[i]}`;
  433. }
  434.  
  435. function getTimestampDateString(timestamp) {
  436. const date = new Date(timestamp);
  437. const year = date.getUTCFullYear().toString();
  438. const month = (date.getUTCMonth() + 1).toString().padStart(2, "0");
  439. const day = date.getUTCDate().toString().padStart(2, "0");
  440. const hour = date.getUTCHours().toString().padStart(2, "0");
  441. const minute = date.getUTCMinutes().toString().padStart(2, "0");
  442. const seconds = date.getUTCSeconds().toString().padStart(2, "0");
  443. return `${year}-${month}-${day} ${hour}:${minute}:${seconds}`;
  444. }
  445.  
  446. function toStringOrDefault(value, defaultValue) {
  447. return typeof(value) === "string" ? value : defaultValue;
  448. }
  449.  
  450. function toNumberOrDefault(value, defaultValue) {
  451. return Number.isNaN(value) ? defaultValue : value;
  452. }
  453.  
  454. function toParentOrDefault() {
  455. if (dead) return null;
  456. if ($('.gdt2 > a').length) return {gid: $('.gdt2 > a').attr('href').split('/')[4], token: $('.gdt2 > a').attr('href').split('/')[5]};
  457. else return null
  458. }
  459.  
  460. function tagsToCommonJson(tags) {
  461. const result = {};
  462. for (const namespace in tags) {
  463. if (!Object.prototype.hasOwnProperty.call(tags, namespace)) { continue; }
  464. const tagList = tags[namespace];
  465. result[namespace] = [...tagList];
  466. }
  467. return result;
  468. }
  469.  
  470. function getShortTitle(title) {
  471. const prefixTags = /^\s*(\(([^\)]*?)\)|\[([^\]]*?)\]|\{([^\}]*?)\})\s*/i;
  472. const suffixTags = /\s*(\(([^\)]*?)(?:\)|$)|\[([^\]]*?)(?:\]|$)|\{([^\}]*?)(?:\}|$))\s*$/i;
  473.  
  474. let m;
  475. while ((m = prefixTags.exec(title))) {
  476. title = title.substr(m.index + m[0].length);
  477. }
  478. while ((m = suffixTags.exec(title))) {
  479. title = title.substr(0, m.index);
  480. }
  481. return title;
  482. }
  483.  
  484. function getGalleryUrl(id) {
  485. const loc = window.location;
  486. return `${loc.protocol}//${loc.host}/g/${id.gid}/${id.token}/`;
  487. }
  488. /** ------------ */
  489.  
  490. $(`<style data-jqstyle="exressurect">
  491. #menu {
  492. font-size: 10pt;
  493. padding: 0.5em 0 0 0;
  494. margin: 3px 5px 5px 0px;
  495. position: relative;
  496. display: inline-block;
  497. width: 100%;
  498. border-top: 1px solid #000;
  499. }
  500. .menuControl {
  501. border: none;
  502. background: rgba(0,0,0,0);
  503. cursor: pointer;
  504. color: #DDD;
  505. }
  506. .menuControl:hover {
  507. color: #EEE;
  508. }
  509. .menuContent {
  510. display: none;
  511. flex-direction: column;
  512. position: absolute;
  513. font-size: 10pt;
  514. border: 1px solid #000;
  515. text-align: left;
  516. overflow: auto;
  517. z-index: 999;
  518. background: rgb(79, 83, 91);
  519. }
  520. .menuContent a {
  521. padding: .25em 1em;
  522. line-height: 1.375em;
  523. text-decoration: none;
  524. }
  525. .menuContent a:hover {
  526. background: rgba(0,0,0,0.4);
  527. }
  528. </style>`).appendTo('head');
  529. })();