IGGGAMES - Show Modified Time for Posts

So you can tell if something is really updated. Also for PCGamesTorrents. Also trims post title and description.

当前为 2022-06-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name IGGGAMES - Show Modified Time for Posts
  3. // @description So you can tell if something is really updated. Also for PCGamesTorrents. Also trims post title and description.
  4. // @namespace RainSlide
  5. // @author RainSlide
  6. // @license AGPL-3.0-or-later
  7. // @version 1.2
  8. // @icon https://igg-games.com/favicon.ico
  9. // @match https://igg-games.com/*
  10. // @match https://pcgamestorrents.com/*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. "use strict";
  15.  
  16. const posts = document.querySelectorAll('article.post[typeof="Article"]');
  17.  
  18. // Show modified time
  19. posts.forEach(post => {
  20.  
  21. const modMeta = post.querySelector(':scope meta[property="dateModified"][content]');
  22. const pubTime = post.querySelector(':scope time');
  23.  
  24. if (modMeta !== null && pubTime !== null) {
  25.  
  26. const dateTime = modMeta.content;
  27. const modDate = new Date(dateTime);
  28.  
  29. // if modDate is not Invalid Date
  30. // modDate.toString() !== "Invalid Date"
  31. if (!Number.isNaN(modDate.getTime())) {
  32. const $ = tagName => document.createElement(tagName);
  33. const textContent = modDate.toLocaleDateString("en-US", { dateStyle: "long" });
  34. const modTime = Object.assign($("time"), { dateTime, textContent });
  35. pubTime.before($("br"), "Published ");
  36. pubTime.after(" | Modified ", modTime, $("br"));
  37. }
  38.  
  39. }
  40.  
  41. });
  42.  
  43. // Trim title and description
  44. const titleSelector = '.uk-article-title' + (posts.length > 1 ? ' > a:only-child' : '');
  45. const descSelector = '.uk-article-meta + div[property="text"] > p:first-child';
  46.  
  47. // trimTitle(post)
  48. // just for igg-games.com, pcgamestorrents.com's titles are fine
  49. const trimTitle = post => {
  50. const title = post.querySelector(':scope ' + titleSelector);
  51. if (title !== null && title.textContent.endsWith(" Free Download")) {
  52. title.textContent = title.textContent.replace(/ Free Download$/, "");
  53. }
  54. return title.textContent; // for trimDesc() of igg-games.com
  55. }
  56.  
  57. // trimDesc(post, text)
  58. const trimDesc = (post, text) => {
  59. const desc = post.querySelector(':scope ' + descSelector);
  60. if (desc !== null && desc.textContent.includes(text)) {
  61. desc.textContent = desc.textContent.replace(text, "");
  62. }
  63. };
  64.  
  65. switch (location.hostname) {
  66. case "igg-games.com":
  67. posts.forEach(post => {
  68. const gameName = trimTitle(post);
  69. trimDesc(post, gameName + " Free Download PC Game Cracked in Direct Link and Torrent. ");
  70. });
  71. break;
  72. case "pcgamestorrents.com":
  73. posts.forEach(post => trimDesc(post, "TORRENT – FREE DOWNLOAD – CRACKED "));
  74. break;
  75. }