Greasy Fork 支持简体中文。

SG Game Tags

some tags of the game in Steamgifts.

目前為 2017-01-09 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name SG Game Tags
  3. // @namespace https://steamcommunity.com/id/Ruphine/
  4. // @version 3.4.1
  5. // @description some tags of the game in Steamgifts.
  6. // @author Ruphine
  7. // @match *://www.steamgifts.com/*
  8. // @icon https://cdn.steamgifts.com/img/favicon.ico
  9. // @connect steampowered.com
  10. // @connect ruphine.esy.es
  11. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js
  12. // @require https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.min.js
  13. // @grant GM_deleteValue
  14. // @grant GM_getValue
  15. // @grant GM_listValues
  16. // @grant GM_setValue
  17. // @grant GM_xmlhttpRequest
  18. // ==/UserScript==
  19.  
  20. /*jshint multistr: true */
  21.  
  22. /* Constant Variables */
  23. const linkGameAPI = "http://store.steampowered.com/api/appdetails?appids=";//filters=categories,platforms,genres&
  24. const linkPackAPI = "http://store.steampowered.com/api/packagedetails?packageids=";
  25. const linkBundleAPI = "http://www.ruphine.esy.es/steamgifts/GetBundleStatus.php"; //?AppID=325470
  26. const linkUserAPI = "http://store.steampowered.com/dynamicstore/userdata/";
  27.  
  28. //p for properties
  29. const pBundle = {
  30. class : "tags_bundle",
  31. text : "Bundled",
  32. text2 : "Not-Bundled",
  33. title : "Bundled since ",
  34. min : "B",
  35. min2 : "NB",
  36. link : "https://www.steamgifts.com/bundle-games/search?q=",
  37. color1 : "#E9202A",
  38. color2 : "#FFFFFF"
  39. };
  40. const pCard = {
  41. class : "tags_card",
  42. text : "Trading Cards",
  43. title : "This game has trading cards",
  44. min : "T",
  45. link : "http://www.steamcardexchange.net/index.php?inventorygame-appid-",
  46. color1 : "#3AA435",
  47. color2 : "#FFFFFF"
  48. };
  49. const pAchievement = {
  50. class : "tags_achievement",
  51. text : "Achievements",
  52. title : "This game has steam achievements",
  53. min : "A",
  54. link : "http://steamcommunity.com/stats/", // 424280/achievements/";
  55. color1 : "#305AC9",
  56. color2 : "#FFFFFF"
  57. };
  58. const pWishlist = {
  59. class : "tags_wishlist",
  60. text : "Wishlist",
  61. title : "This game is in your Steam wishlist",
  62. min : "W",
  63. link : "https://www.steamgifts.com/account/steam/wishlist/search?q=",
  64. color1 : "#9335F1",
  65. color2 : "#FFFFFF"
  66. };
  67. const pLinux = {
  68. class : "tags_linux",
  69. text : "Linux",
  70. title : "Linux supported",
  71. min : "L",
  72. color1 : "#E67300",
  73. color2 : "#FFFFFF"
  74. };
  75. const pMac = {
  76. class : "tags_mac",
  77. text : "Mac",
  78. title : "Mac Supported",
  79. min : "M",
  80. color1 : "#777777",
  81. color2 : "#FFFFFF"
  82. };
  83. const pEarly = {
  84. class : "tags_early",
  85. text : "Early Access",
  86. title : "This game is in early access state",
  87. min : "E",
  88. color1 : "#9FA027",
  89. color2 : "#FFFFFF"
  90. };
  91. const pHidden = {
  92. class : "tags_hidden",
  93. text : "Hidden",
  94. title : "This game is in your filter list",
  95. min : "H",
  96. link : "https://www.steamgifts.com/account/settings/giveaways/filters/search?q=",
  97. color1 : "#A0522D",
  98. color2 : "#FFFFFF"
  99. };
  100. const pOwned = {
  101. class : "tags_owned",
  102. text : "Owned",
  103. title : "You already have this game",
  104. min : "O",
  105. color1 : "#444444",
  106. color2 : "#FF9900"
  107. };
  108. const pIgnored = {
  109. class : "tags_ignored",
  110. text : "Ignored",
  111. title : "You marked this game as not interested",
  112. min : "X",
  113. color1 : "#E06666",
  114. color2 : "#FFFFFF"
  115. };
  116.  
  117. /* CSS */
  118. const myCSS = '\
  119. .tags { \
  120. text-decoration: none; \
  121. border-radius: 4px; \
  122. padding: 2px 5px; \
  123. font-size: 8pt; \
  124. margin: 3px 3px 3px 0px; \
  125. text-shadow: none; \
  126. display: none; \
  127. white-space: nowrap; \
  128. } \
  129. .tags.minimalist { \
  130. margin-right: 0; \
  131. margin-left: 5px; \
  132. } \
  133. .' + pBundle.class + ' { \
  134. background-color: ' + GM_getValue("bundle-1", pBundle.color1) + '; \
  135. color: ' + GM_getValue("bundle-2", pBundle.color2) + '; \
  136. } \
  137. .' + pCard.class + ' { \
  138. background-color: ' + GM_getValue("card-1", pCard.color1) + '; \
  139. color: ' + GM_getValue("card-2", pCard.color2) + '; \
  140. } \
  141. .' + pAchievement.class + ' { \
  142. background-color: ' + GM_getValue("achievement-1", pAchievement.color1) + '; \
  143. color: ' + GM_getValue("achievement-2", pAchievement.color2) + '; \
  144. } \
  145. .' + pWishlist.class + ' { \
  146. background-color: ' + GM_getValue("wishlist-1", pWishlist.color1) + '; \
  147. color: ' + GM_getValue("wishlist-2", pWishlist.color2) + '; \
  148. } \
  149. .' + pLinux.class + ' { \
  150. background-color: ' + GM_getValue("linux-1", pLinux.color1) + '; \
  151. color: ' + GM_getValue("linux-2", pLinux.color2) + '; \
  152. } \
  153. .' + pMac.class + ' { \
  154. background-color: ' + GM_getValue("mac-1", pMac.color1) + '; \
  155. color: ' + GM_getValue("mac-2", pMac.color2) + '; \
  156. } \
  157. .' + pEarly.class + ' { \
  158. background-color: ' + GM_getValue("early-1", pEarly.color1) + '; \
  159. color: ' + GM_getValue("early-2", pEarly.color2) + '; \
  160. } \
  161. .' + pHidden.class + ' { \
  162. background-color: ' + GM_getValue("hidden-1", pHidden.color1) + '; \
  163. color: ' + GM_getValue("hidden-2", pHidden.color2) + '; \
  164. } \
  165. .' + pOwned.class + ' { \
  166. background-color: ' + GM_getValue("owned-1", pOwned.color1) + '; \
  167. color: ' + GM_getValue("owned-2", pOwned.color2) + '; \
  168. } \
  169. .' + pIgnored.class + ' { \
  170. background-color: ' + GM_getValue("ignored-1", pIgnored.color1) + '; \
  171. color: ' + GM_getValue("ignored-2", pIgnored.color2) + '; \
  172. } \
  173. ';
  174. $("head").append('<style type="text/css">' + myCSS + '</style>');
  175.  
  176. const THIS_URL = window.location.href;
  177. const TIMEOUT = 0;
  178. const CACHE_TIME = 6*60*60*1000; //6 hours
  179.  
  180. var cbCards = GM_getValue("cbCards", true);
  181. var cbAchievement = GM_getValue("cbAchievement", true);
  182. var cbBundled = GM_getValue("cbBundled", true);
  183. var cbWishlist = GM_getValue("cbWishlist", true);
  184. var cbLinux = GM_getValue("cbLinux", false);
  185. var cbMac = GM_getValue("cbMac", false);
  186. var cbEarly = GM_getValue("cbEarly", false);
  187. var cbHidden = GM_getValue("cbHidden", true);
  188. var cbOwned = GM_getValue("cbOwned", true);
  189. var cbIgnored = GM_getValue("cbIgnored", false);
  190.  
  191. var cbTagStyle = GM_getValue("cbTagStyle", 1); //1 = full, 2 = minimalist
  192.  
  193. var BundledGames = GM_getValue("BundledGames", "");
  194. var BundledCache = GM_getValue("BundledCache", 0);
  195. var UserdataAPI = GM_getValue("UserdataAPI", "");
  196. var UserdataCache = GM_getValue("UserdataCache", 0);
  197. var GameData = GM_getValue("GameData", "");
  198. var PackageData = GM_getValue("PackageData", "");
  199.  
  200. var rgWishlist, rgOwnedApps, rgOwnedPackages, rgIgnoredApps, rgIgnoredPackages;
  201. var arrBundled;
  202.  
  203. if(cbBundled && BundledCache < Date.now() - CACHE_TIME) // Check if need to request bundle list from ruphine API
  204. getBundleList();
  205. else if((cbWishlist || cbOwned || cbIgnored) && UserdataCache < Date.now() - CACHE_TIME) //6 hours. Check if need to request steam user api
  206. getUserdata();
  207. else
  208. main();
  209.  
  210. function main()
  211. {
  212. try {
  213. arrBundled = JSON.parse(BundledGames);
  214. }
  215. catch (e) {
  216. console.log("[SG Game Tags] Invalid json format for Bundle List");
  217. BundledGames = ""; GM_setValue("BundledGames", "");
  218. BundledCache = 0; GM_setValue("BundledCache", 0);
  219. }
  220.  
  221. try {
  222. var userdata = JSON.parse(UserdataAPI);
  223. rgWishlist = userdata.rgWishlist;
  224. rgOwnedApps = userdata.rgOwnedApps;
  225. rgOwnedPackages = userdata.rgOwnedPackages;
  226. rgIgnoredApps = userdata.rgIgnoredApps;
  227. rgIgnoredPackages = userdata.rgIgnoredPackages;
  228.  
  229. }
  230. catch (e) {
  231. console.log("[SG Game Tags] Invalid json format for UserdataAPI");
  232. UserdataAPI = ""; GM_setValue("UserdataAPI", "");
  233. UserdataCache = 0; GM_setValue("UserdataCache", 0);
  234. }
  235.  
  236. if(GameData === "")
  237. PrepareJSON();
  238. else
  239. {
  240. GameData = JSON.parse(GameData);
  241. PackageData = JSON.parse(PackageData);
  242. }
  243.  
  244. var observer;
  245. var config = {childList: true, attributes: false, characterData: false, subtree: true};
  246. if(/www.steamgifts.com\/giveaways\/new/.test(THIS_URL)) // process giveaway creation page
  247. InitGiveawayCreationPage();
  248. else if(/www.steamgifts.com\/account\/*/.test(THIS_URL))
  249. {
  250. var sidebar_item = '<li class="sidebar__navigation__item">\
  251. <a class="sidebar__navigation__item__link" href="/sg-game-tags">\
  252. <div class="sidebar__navigation__item__name">SG Game Tags</div>\
  253. <div class="sidebar__navigation__item__underline"></div>\
  254. </a>\
  255. </li>';
  256. $($(".sidebar__navigation")[2]).append(sidebar_item);
  257. }
  258. else if(/www.steamgifts.com\/sg-game-tags/.test(THIS_URL)) // process sg game tags setting page
  259. initSetting();
  260. else if(/www.steamgifts.com\/($|giveaways$|giveaways\/search)/.test(THIS_URL)) // homepage and all search active giveaway
  261. {
  262. ProcessGiveawayListPage($(".widget-container"));
  263. // handles element added later by endless scroll, add timeout to delay this function because it is triggered when ext SG runs
  264. observer = new MutationObserver(function(mutations)
  265. {
  266. $.each(mutations, function(index, mutation){
  267. ProcessGiveawayListPage(mutation.addedNodes);
  268. });
  269. });
  270. $(".widget-container>div").each(function(index, element){
  271. observer.observe(element, config);
  272. });
  273.  
  274. if($(".featured__inner-wrap .global__image-outer-wrap--missing-image").length === 0 && $(".featured__inner-wrap a img").length > 0)
  275. ProcessFeaturedGiveaway($(".featured__inner-wrap a img")[0].src);
  276. }
  277. // user profile & group page excluding user trade and feedback and excluding group users, stats, and wishlist
  278. else if(/www.steamgifts.com\/(user|group)\//.test(THIS_URL) && !/user\/\w+\/(feedback|trade)/.test(THIS_URL) && !/group\/\w+\/\w+\/(users|stats|wishlist)/.test(THIS_URL)) // exclude some pages
  279. {
  280. ProcessGiveawayListPage($(".widget-container"));
  281. // handles element added later by endless scroll, add timeout to delay this function because it is triggered when ext SG runs
  282. observer = new MutationObserver(function(mutations)
  283. {
  284. $.each(mutations, function(index, mutation){
  285. ProcessGiveawayListPage(mutation.addedNodes);
  286. });
  287. });
  288. $(".widget-container>div").each(function(index, element){
  289. observer.observe(element, config);
  290. });
  291.  
  292. if($(".featured__inner-wrap .global__image-outer-wrap--missing-image").length === 0 && $(".featured__inner-wrap a img").length > 0)
  293. ProcessFeaturedGiveaway($(".featured__inner-wrap a img")[0].src);
  294. }
  295. else if(/www.steamgifts.com\/giveaway\//.test(THIS_URL)) // giveaway page https://www.steamgifts.com/giveaway/FGbTw/left-4-dead-2
  296. ProcessFeaturedGiveaway($(".featured__inner-wrap a")[0].href);
  297.  
  298. // https://www.steamgifts.com/sales*
  299. // https://www.steamgifts.com/sales/account/steam/games
  300. // https://www.steamgifts.com/sales/account/steam/wishlist
  301. // https://www.steamgifts.com/giveaways/created
  302. // https://www.steamgifts.com/giveaways/entered
  303. // https://www.steamgifts.com/giveaways/won
  304. // https://www.steamgifts.com/giveaways/wishlist
  305. // https://www.steamgifts.com/account/settings/giveaways/filters
  306. else if(/www.steamgifts.com\/(sales|account\/steam\/(games|wishlist)|giveaways\/(created|entered|won|wishlist)|account\/settings\/giveaways\/filters|group\/\w+\/\w+\/wishlist)/.test(THIS_URL))
  307. {
  308. ProcessGameListPage($(".widget-container"));
  309. observer = new MutationObserver(function(mutations)
  310. {
  311. $.each(mutations, function(index, mutation){
  312. ProcessGameListPage(mutation.addedNodes);
  313. });
  314. });
  315. $(".widget-container>div").each(function(index, element){
  316. observer.observe(element, config);
  317. });
  318. }
  319.  
  320. AddShortcutToSettingPage();
  321. }
  322.  
  323. function ProcessFeaturedGiveaway(URL)
  324. {
  325. if(cbBundled || cbCards || cbAchievement || cbHidden || cbWishlist || cbLinux || cbMac || cbEarly) // check if at least one tag enabled
  326. {
  327. var Name = $(".featured__heading__medium").text().substring(0,45); //letter after 45th converted to ...
  328. var $Target = $(".featured__heading");
  329. ProcessTags($Target, URL, Name);
  330. }
  331. }
  332.  
  333. function ProcessGiveawayListPage(parent) // giveaways list with creator name
  334. {
  335. if(cbBundled || cbCards || cbAchievement || cbHidden || cbWishlist || cbLinux || cbMac || cbEarly) // check if at least one tag enabled
  336. {
  337. $(parent).find(".giveaway__row-inner-wrap").each(function(index, element)
  338. {
  339. var URL = $(element).find(".giveaway__heading>a.giveaway__icon").attr("href");
  340. if(URL !== undefined)
  341. {
  342. var Name = $(element).find(".giveaway__heading__name").contents().filter(
  343. function() //return text without [NEW] and [FREE]
  344. {
  345. return this.nodeType === 3; //Node.TEXT_NODE
  346. }
  347. ).slice(-1)[0].textContent.substring(0,40); //letter after 40th converted to ...
  348. var $Target = $(element).find(".giveaway__heading");
  349. ProcessTags($Target, URL, Name);
  350. }
  351. });
  352. }
  353. }
  354.  
  355. function ProcessGameListPage(parent) // giveaways / games list
  356. {
  357. if(cbBundled || cbCards || cbAchievement || cbHidden || cbWishlist || cbLinux || cbMac || cbEarly) // check if at least one tag enabled
  358. {
  359. $(parent).find(".table__row-inner-wrap").each(function(index, element)
  360. {
  361. var URL;
  362. if(/www.steamgifts.com\/account\/settings\/giveaways\/filters/.test(THIS_URL))
  363. URL = $(element).find("a.table__column__secondary-link").text();
  364. else
  365. URL = $($(element).find(".global__image-inner-wrap")[0]).css('background-image');
  366.  
  367. if(URL !== undefined)
  368. {
  369. URL = URL.replace('url(', '').replace(')', '');
  370. var Name = $(element).find(".table__column__heading").text().substring(0,30);
  371. var $Target = $(element).find(".table__column--width-fill > :first-child");
  372.  
  373. if(/www.steamgifts.com\/sales/.test(THIS_URL))
  374. $Target.css("display", "block"); //because sales pages don't use <p> thus tags will appears in line with title
  375.  
  376. ProcessTags($Target, URL, Name);
  377. }
  378. });
  379. }
  380. }
  381.  
  382. function ProcessTags($Target, URL, Name)
  383. {
  384. var ID = getAppIDfromLink(URL);
  385. Name = encodeURIComponent(Name); //encode special characters that may break search params
  386. var linkStore = "";
  387. if(isApp(URL))
  388. linkStore = "http://store.steampowered.com/app/" + ID;
  389. else if(isPackage(URL))
  390. linkStore = "http://store.steampowered.com/sub/" + ID;
  391.  
  392. var $tagBundle, $tagCard, $tagAchievement, $tagWishlist, $tagLinux, $tagMac, $tagEarly, $tagHidden, $tagOwned, $tagIgnored, $tagOther;
  393. if(cbTagStyle == 1)
  394. {
  395. if(cbBundled == 1)
  396. $tagBundle = createTag(pBundle.class, pBundle.title, pBundle.text, pBundle.link+Name, $Target);
  397. else
  398. $tagBundle = createTag(pBundle.class, "", pBundle.text2, pBundle.link+Name, $Target);
  399.  
  400. $tagCard = createTag(pCard.class, pCard.title, pCard.text, pCard.link+ID, $tagBundle);
  401. $tagAchievement = createTag(pAchievement.class, pAchievement.title, pAchievement.text, pAchievement.link+ID+"/achievements/", $tagCard);
  402. $tagWishlist = createTag(pWishlist.class, pWishlist.title, pWishlist.text, pWishlist.link+Name, $tagAchievement);
  403. $tagLinux = createTag(pLinux.class, pLinux.title, pLinux.text, linkStore, $tagWishlist);
  404. $tagMac = createTag(pMac.class, pMac.title, pMac.text, linkStore, $tagLinux);
  405. $tagEarly = createTag(pEarly.class, pEarly.title, pEarly.text, linkStore, $tagMac);
  406. $tagOwned = createTag(pOwned.class, pOwned.title, pOwned.text, linkStore, $tagEarly);
  407. $tagIgnored = createTag(pIgnored.class, pIgnored.title, pIgnored.text, linkStore, $tagOwned);
  408. }
  409. else
  410. {
  411. if(cbBundled == 1)
  412. $tagBundle = createTag(pBundle.class + " minimalist", pBundle.title, pBundle.min, pBundle.link+Name, $Target);
  413. else
  414. $tagBundle = createTag(pBundle.class + " minimalist", "", pBundle.min2, pBundle.link+Name, $Target);
  415.  
  416. $tagCard = createTag(pCard.class + " minimalist", pCard.title, pCard.min, pCard.link+ID, $Target);
  417. $tagAchievement = createTag(pAchievement.class + " minimalist", pAchievement.title, pAchievement.min, pAchievement.link+ID+"/achievements/", $Target);
  418. $tagWishlist = createTag(pWishlist.class + " minimalist", pWishlist.title, pWishlist.min, pWishlist.link+Name, $Target);
  419. $tagLinux = createTag(pLinux.class + " minimalist", pLinux.title, pLinux.min, linkStore, $Target);
  420. $tagMac = createTag(pMac.class + " minimalist", pMac.title, pMac.min, linkStore, $Target);
  421. $tagEarly = createTag(pEarly.class + " minimalist", pEarly.title, pEarly.min, linkStore, $Target);
  422. $tagOwned = createTag(pOwned.class + " minimalist", pOwned.title, pOwned.min, linkStore, $Target);
  423. $tagIgnored = createTag(pIgnored.class + " minimalist", pIgnored.title, pIgnored.min, linkStore, $Target);
  424. }
  425.  
  426. if(/www.steamgifts.com\/giveaway\//.test(THIS_URL)) //only trigger inside giveaway page, no need for homepage
  427. {
  428. if(cbTagStyle == 1)
  429. $tagHidden = createTag(pHidden.class, pHidden.title, pHidden.text, pHidden.link+Name, $tagIgnored);
  430. else if(cbTagStyle == 2)
  431. $tagHidden = createTag(pHidden.class + " minimalist", pHidden.title, pHidden.min, pHidden.link+Name, $Target);
  432.  
  433. getHiddenStatus(ID, Name, $tagHidden);
  434. }
  435.  
  436. if(isApp(URL))
  437. getSteamCategories(ID, $tagCard, $tagAchievement, $tagLinux, $tagMac, $tagEarly);
  438. else if(isPackage(URL))
  439. {
  440. $tagCard.attr("href", "");
  441. $tagAchievement.attr("href", "");
  442. getSteamCategoriesFromPackage(ID, $tagCard, $tagAchievement, $tagLinux, $tagMac, $tagEarly);
  443. }
  444.  
  445. var type = isApp(URL) ? 'app' : 'sub';
  446. if(cbBundled && BundledGames !== "")
  447. getBundleStatus(ID, type, $tagBundle);
  448. if(UserdataAPI !== "")
  449. {
  450. if(cbWishlist)
  451. getWishlistStatus(ID, $tagWishlist);
  452. if(cbOwned)
  453. getOwnedStatus(ID, $tagOwned, (type == 'app'));
  454. if(cbIgnored)
  455. getIgnoredStatus(ID, $tagIgnored, (type == 'app'));
  456. }
  457. }
  458.  
  459. function createTag(_class, title, text, href, $divTarget)
  460. {
  461. var $tag = $('<a target="_blank" class="tags ' + _class +'" title="' + title + '" href="' + href + '">' + text + '</a>');
  462.  
  463. if(cbTagStyle == 1 || /www.steamgifts.com\/giveaways\/new/.test(THIS_URL)) // full text below game title, use after, or bundle tag in giveaway creation page
  464. $divTarget.after($tag);
  465. else if(cbTagStyle == 2) // minimalist beside game title use append
  466. $divTarget.append($tag);
  467. return $tag;
  468. }
  469.  
  470. function getSteamCategories(appID, $tagCard, $tagAchievement, $tagLinux, $tagMac, $tagEarly, packID = "0")
  471. {
  472. var needRequest = false;
  473. if(GameData[appID] === undefined)
  474. {
  475. var template = {"cards": false, "achievement": false, "mac": false, "linux": false, "early_access": false, "last_checked": 0, "game": appID+""};
  476. GameData[appID] = template;
  477. needRequest = true;
  478. }
  479. else
  480. {
  481. var data = GameData[appID];
  482. if(cbCards && data.cards)
  483. {
  484. $tagCard.css("display", "inline-block");
  485. $tagCard.css("display", "inline-block");
  486. $tagCard.attr("href", pCard.link+GameData[appID].game);
  487. }
  488. if(cbAchievement && data.achievement)
  489. {
  490. $tagAchievement.css("display", "inline-block");
  491. $tagAchievement.attr("href", pAchievement.link+GameData[appID].game+"/achievements/");
  492. }
  493. if(cbMac && data.mac)
  494. $tagMac.css("display", "inline-block");
  495. if(cbLinux && data.linux)
  496. $tagLinux.css("display", "inline-block");
  497.  
  498. if(data.last_checked < (Date.now() - (24 * 60 * 60 * 1000))) // 24 hours have passed since last checked
  499. {
  500. if((!data.cards && cbCards) || (!data.achievement && cbAchievement) || (!data.mac && cbMac ) || (!data.linux && cbLinux) || (data.early_access && cbEarly))
  501. needRequest = true;
  502. }
  503. else if(data.early_access && cbEarly)
  504. $tagEarly.css("display", "inline-block");
  505. }
  506. if(needRequest)
  507. {
  508. var link = linkGameAPI+appID;
  509. if(GameData[appID].last_checked !== 0 || (packID != "0" && PackageData[packID].last_checked !== 0)) //if not first time checked, filter out the request
  510. link += "&filters=categories,platforms,genres";
  511.  
  512. // console.log("[SG Game Tags] requesting " + link);
  513.  
  514. GM_xmlhttpRequest({
  515. method: "GET",
  516. timeout: 10000,
  517. url: link,
  518. onload: function(data)
  519. {
  520. var obj = JSON.parse(data.responseText)[appID].data;
  521. if(obj !== undefined) // undefined = doesn't have store page or doesn't exist
  522. // get steam apps categories : achievement, trading cards, etc
  523. {
  524. if (obj.type !== undefined && obj.type != "game") //if it is DLC, obj will have different fullgame.appid
  525. {
  526. GameData[appID].game = obj.fullgame.appid;
  527. //set tagcard and tagachievement href to the main game appid
  528. $tagCard.attr("href", pCard.link+obj.fullgame.appid);
  529. $tagAchievement.attr("href", pAchievement.link+obj.fullgame.appid+"/achievements/");
  530. }
  531. else if(packID != "0" && PackageData[packID].games.indexOf(appID) == -1)
  532. PackageData[packID].games.push(appID);
  533.  
  534. var categories = obj.categories;
  535. if(categories !== undefined)
  536. {
  537. var catCards = $.grep(categories, function(e){ return e.id == "29"; });
  538. if(catCards.length > 0)
  539. {
  540. if(cbCards) $tagCard.css("display", "inline-block");
  541. GameData[appID].cards = true;
  542. if(packID != "0")
  543. {
  544. PackageData[packID].cards = true;
  545. if(PackageData[packID].games.length > 1)
  546. $tagCard.attr("href", "http://ruphine.esy.es/steamgifts/TradingCard.php?packageid="+packID);
  547. else
  548. $tagCard.attr("href", pCard.link+PackageData[packID].games[0]);
  549. }
  550. }
  551.  
  552. var catAchievement = $.grep(categories, function(e){ return e.id == "22"; });
  553. if(catAchievement.length > 0)
  554. {
  555. GameData[appID].achievement = true;
  556. if(cbAchievement)
  557. $tagAchievement.css("display", "inline-block");
  558. if(packID != "0")
  559. {
  560. PackageData[packID].achievement = true;
  561. if(PackageData[packID].games.length > 1)
  562. $tagAchievement.attr("href", "http://ruphine.esy.es/steamgifts/Achievement.php?packageid="+packID);
  563. else
  564. $tagAchievement.attr("href", pAchievement.link+PackageData[packID].games[0]+"/achievements/");
  565. }
  566. }
  567. }
  568.  
  569. // get steam apps platforms: linux: boolean, mac: boolean
  570. var platforms = obj.platforms;
  571. if(platforms.linux)
  572. {
  573. GameData[appID].linux = true;
  574. if(cbLinux)
  575. $tagLinux.css("display", "inline-block");
  576. if(packID != "0")
  577. PackageData[packID].linux = true;
  578. }
  579. if(platforms.mac)
  580. {
  581. GameData[appID].mac = true;
  582. if(cbMac)
  583. $tagMac.css("display", "inline-block");
  584. if(packID != "0")
  585. PackageData[packID].mac = true;
  586. }
  587.  
  588. // get steam apps genres
  589. if(obj.genres !== undefined)
  590. {
  591. var genEarly = $.grep(obj.genres, function(e){ return e.id == "70"; });
  592. if(genEarly.length > 0)
  593. {
  594. GameData[appID].early_access = true;
  595. if(cbEarly)
  596. $tagEarly.css("display", "inline-block");
  597. if(packID != "0")
  598. PackageData[packID].early_access = true;
  599. }
  600. else
  601. {
  602. GameData[appID].early_access = false;
  603. if(packID != "0")
  604. PackageData[packID].early_access = false;
  605. }
  606. }
  607. }
  608. GameData[appID].last_checked = Date.now();
  609. GM_setValue("GameData", JSON.stringify(GameData));
  610.  
  611. if(packID != "0")
  612. {
  613. PackageData[packID].last_checked = Date.now();
  614. GM_setValue("PackageData", JSON.stringify(PackageData));
  615. }
  616. },
  617. ontimeout: function(data)
  618. {
  619. console.log("[SG Game Tags] Request " + linkGameAPI+appID + " Timeout");
  620. }
  621. });
  622. }
  623. }
  624.  
  625. function getBundleStatus(appID, type, $tag)
  626. {
  627. var Game = $.grep(arrBundled, function(e){ return (e.AppID == appID && e.Type == type); });
  628. if(Game.length > 0 && cbBundled == 1) //game found in bundle list
  629. {
  630. $tag.css("display", "inline-block");
  631. $tag.attr("title", pBundle.title+Game[0].BundledDate);
  632. }
  633. else if(Game.length == 0 && cbBundled == 2)
  634. $tag.css("display", "inline-block");
  635. }
  636.  
  637. function getBundleList()
  638. {
  639. // console.log("[SG Game Tags] requesting " + linkBundleAPI);
  640. GM_xmlhttpRequest({
  641. method: "GET",
  642. timeout: 10000,
  643. url: linkBundleAPI,
  644. onload: function(data)
  645. {
  646. BundledGames = data.responseText;
  647. GM_setValue("BundledGames", BundledGames);
  648.  
  649. BundledCache = Date.now();
  650. GM_setValue("BundledCache", BundledCache);
  651.  
  652. if((cbWishlist || cbOwned || cbIgnored) && UserdataCache < Date.now() - CACHE_TIME)
  653. getUserdata();
  654. else
  655. main();
  656. },
  657. ontimeout: function(data)
  658. {
  659. console.log("[SG Game Tags] Request " + linkBundleAPI + " Timeout");
  660. if((cbWishlist || cbOwned || cbIgnored) && UserdataCache < Date.now() - CACHE_TIME)
  661. getUserdata();
  662. else
  663. main();
  664. }
  665. });
  666. }
  667.  
  668. function getUserdata()
  669. {
  670. // console.log("[SG Game Tags] requesting " + linkUserAPI);
  671. GM_xmlhttpRequest({
  672. method: "GET",
  673. timeout: 10000,
  674. url: linkUserAPI,
  675. onload: function(data)
  676. {
  677. var result = JSON.parse(data.responseText);
  678. if(result.rgOwnedApps.length !== 0) //check if user logged in
  679. {
  680. UserdataAPI = data.responseText;
  681. GM_setValue("UserdataAPI", UserdataAPI);
  682.  
  683. UserdataCache = Date.now();
  684. GM_setValue("UserdataCache", UserdataCache);
  685. }
  686. else
  687. console.log("[SG Game Tags] Unable to get user's steam data. User is not logged in to steam.");
  688.  
  689. main();
  690. },
  691. ontimeout: function(data)
  692. {
  693. console.log("[SG Game Tags] Request " + linkUserAPI + " Timeout");
  694. main();
  695. }
  696. });
  697. }
  698.  
  699. function getHiddenStatus(appID, appName, $elems)
  700. {
  701. if(cbHidden)
  702. {
  703. // console.log("[SG Game Tags] requesting " + pHidden.link+appName);
  704. $.get(pHidden.link+appName, function(data)
  705. {
  706. var gamesfound = $(data).find("a.table__column__secondary-link");
  707. for(i=0; i<$(gamesfound).length; i++)
  708. {
  709. var url = $(gamesfound)[i].href;
  710. var ID = getAppIDfromLink(url);
  711. if(appID == ID)
  712. {
  713. //TODO : Save appID + true ke local cache
  714. $elems.css("display", "inline-block");
  715. return true; //exit function
  716. }
  717. }
  718. });
  719. }
  720. }
  721.  
  722. function getWishlistStatus(appID, $elems)
  723. {
  724. appID = parseInt(appID);
  725. if(rgWishlist.indexOf(appID) >= 0)
  726. $elems.css("display", "inline-block");
  727. }
  728.  
  729. function getOwnedStatus(appID, $elems, isApp)
  730. {
  731. appID = parseInt(appID);
  732. if(isApp && rgOwnedApps.indexOf(appID) >= 0)
  733. $elems.css("display", "inline-block");
  734. else if(!isApp && rgOwnedPackages.indexOf(appID) >= 0)
  735. $elems.css("display", "inline-block");
  736. }
  737.  
  738. function getIgnoredStatus(appID, $elems, isApp)
  739. {
  740. appID = parseInt(appID);
  741. if(isApp && rgIgnoredApps.indexOf(appID) >= 0)
  742. $elems.css("display", "inline-block");
  743. else if(!isApp && rgIgnoredPackages.indexOf(appID) >= 0)
  744. $elems.css("display", "inline-block");
  745. }
  746.  
  747. function getSteamCategoriesFromPackage(packID, $tagCard, $tagAchievement, $tagLinux, $tagMac, $tagEarly)
  748. {
  749. var needRequest = false;
  750. if(PackageData[packID] === undefined || PackageData[packID].games === undefined)
  751. {
  752. var template = {"cards": false, "achievement": false, "mac": false, "linux": false, "early_access": false, "last_checked": 0, "games":[]};
  753. PackageData[packID] = template;
  754. needRequest = true;
  755. }
  756. else
  757. {
  758. var data = PackageData[packID];
  759. if(cbCards && data.cards)
  760. {
  761. $tagCard.css("display", "inline-block");
  762. if(data.games.length > 1)
  763. {
  764. $tagCard.attr("href", "http://ruphine.esy.es/steamgifts/TradingCard.php?packageid="+packID);
  765. $tagCard.attr("title", "There is " + data.games.length + " games in this package, and at least one of them have trading cards");
  766. }
  767. else
  768. $tagCard.attr("href", pCard.link+data.games[0]);
  769. }
  770. if(cbAchievement && data.achievement)
  771. {
  772. $tagAchievement.css("display", "inline-block");
  773. if(data.games.length > 1)
  774. {
  775. $tagAchievement.attr("href", "http://ruphine.esy.es/steamgifts/Achievement.php?packageid="+packID);
  776. $tagAchievement.attr("title", "There is " + data.games.length + " games in this package, and at least one of them have achievements");
  777. }
  778. else
  779. $tagAchievement.attr("href", pAchievement.link+data.games[0]+"/achievements/");
  780. }
  781. if(cbMac && data.mac)
  782. $tagMac.css("display", "inline-block");
  783. if(cbLinux && data.linux)
  784. $tagLinux.css("display", "inline-block");
  785. if(cbEarly && data.early_access)
  786. $tagEarly.css("display", "inline-block");
  787.  
  788. if(data.last_checked < (Date.now() - (24 * 60 * 60 * 1000))) // 24 hours have passed since last checked
  789. {
  790. if((!data.cards && cbCards) || (!data.achievement && cbAchievement) || (!data.mac && cbMac ) || (!data.linux && cbLinux) || (data.early_access && cbEarly))
  791. needRequest = true;
  792. }
  793. }
  794. if(needRequest)
  795. {
  796. // console.log("[SG Game Tags] requesting " + linkPackAPI+packID);
  797. GM_xmlhttpRequest({
  798. method: "GET",
  799. timeout: 10000,
  800. url: linkPackAPI+packID,
  801. onload: function(data)
  802. {
  803. var IDs = JSON.parse(data.responseText)[packID].data;
  804. if(IDs === undefined)
  805. {
  806. PackageData[packID].cards = false;
  807. PackageData[packID].achievement = false;
  808. PackageData[packID].mac = false;
  809. PackageData[packID].linux = false;
  810. PackageData[packID].early_access = false;
  811. PackageData[packID].games = [];
  812. PackageData[packID].last_checked = Date.now();
  813. GM_setValue("PackageData", JSON.stringify(PackageData));
  814. }
  815. else
  816. {
  817. IDs = IDs.apps;
  818. $.each(IDs, function(index)
  819. {
  820. getSteamCategories(IDs[index].id, $tagCard, $tagAchievement, $tagLinux, $tagMac, $tagEarly, packID);
  821. });
  822. }
  823. },
  824. ontimeout: function(data)
  825. {
  826. console.log("[SG Game Tags] Request " + linkPackAPI+packID + " Timeout");
  827. }
  828. });
  829. }
  830. }
  831.  
  832. function PrepareJSON()
  833. {
  834. var template = {"cards": false, "achievement": false, "mac": false, "linux": false, "early_access": false, "last_checked": 0};
  835. var a = {"0":template};
  836. var temp = JSON.stringify(a);
  837. GameData = JSON.parse(temp);
  838. PackageData = JSON.parse(temp);
  839. GM_setValue("GameData", JSON.stringify(GameData));
  840. GM_setValue("PackageData", JSON.stringify(PackageData));
  841. }
  842.  
  843. function getAppIDfromLink(link){
  844. var url = link.split("/");
  845. return url[url.length-2];
  846. }
  847.  
  848. function isApp(link){
  849. return /\/app|apps\/0-9\//.test(link);
  850. }
  851.  
  852. function isPackage(link){
  853. return /\/sub|subs\/0-9\//.test(link);
  854. }
  855.  
  856.  
  857. // ========================================== create new giveaway page ========================================================
  858. function InitGiveawayCreationPage()
  859. {
  860. if($(".js__autocomplete-data").length > 0)
  861. {
  862. var observer = new MutationObserver(function(mutations)
  863. {
  864. $(".tags").remove();
  865. var $table = $(mutations[0].addedNodes).find(".table__row-inner-wrap");
  866. $table.each(function(index, element)
  867. {
  868. var url = $(element).find("a.table__column__secondary-link").text();
  869. var ID = getAppIDfromLink(url);
  870. var Name = $(element).find(".table__column__heading").text();
  871. var $Target = $(element).find(".table__column--width-fill");
  872.  
  873. var $tagBundle = createTag(pBundle.class, pBundle.title, pBundle.text, pBundle.link+Name, $Target);
  874. $tagBundle.css("float", "right");
  875.  
  876. var type = isApp(url) ? 'app' : 'sub';
  877. getBundleStatus(ID, type, $tagBundle);
  878. });
  879. $table.on("click", function(event)
  880. {
  881. var url = $(this).find("a.table__column__secondary-link").text();
  882. var ID = getAppIDfromLink(url);
  883. var Name = $(this).find(".table__column__heading").text();
  884. var $Target = $(".js__autocomplete-name");
  885. $tagBundle = createTag(pBundle.class, pBundle.title, pBundle.text, pBundle.link+Name, $Target);
  886. var type = isApp(url) ? 'app' : 'sub';
  887. getBundleStatus(ID, type, $tagBundle);
  888. });
  889. });
  890. var config = {childList: true, attributes: false, characterData: false};
  891. observer.observe($(".js__autocomplete-data")[0], config);
  892. }
  893. }
  894.  
  895. // ========================================== setting page ========================================================
  896. function initSetting()
  897. {
  898. $("head").html('\
  899. <meta charset="UTF-8">\
  900. <link rel="shortcut icon" href="https://cdn.steamgifts.com/img/favicon.ico">\
  901. <title>SG Game Tags Setting</title>\
  902. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">\
  903. <link rel="stylesheet" type="text/css" href="https://cdn.steamgifts.com/css/minified_v18.css">\
  904. <script src="https://cdn.steamgifts.com/js/minified_v15.js"></script>\
  905. <meta name="viewport" content="width=1200">\
  906. <!-- SGGT Import -->\
  907. <style type="text/css">\
  908. .my__checkbox { cursor:pointer; padding:7px 0; } \
  909. .my__checkbox i { margin-right:7px; } \
  910. .my__checkbox:not(:last-of-type) { border-bottom:1px dotted #d2d6e0; } \
  911. .my__checkbox:not(:hover) .form__checkbox__hover,.my__checkbox.is-selected .form__checkbox__hover,.my__checkbox:not(.is-selected) .form__checkbox__selected,.my__checkbox:hover .form__checkbox__default,.my__checkbox.is-selected .form__checkbox__default { \
  912. display:none; \
  913. } \
  914. .row div { display: inline-block; } \
  915. .preview-tags { width: 80px; margin-left: 10px; } \
  916. .row .markdown {margin-left: 10px; cursor: pointer; }\
  917. </style>\
  918. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.min.css" />\
  919. ');
  920. $("head").append('<style type="text/css">' + myCSS + '</style>');
  921. $("body").html("");
  922.  
  923. GM_xmlhttpRequest({
  924. method: "GET",
  925. timeout: 10000,
  926. url: "/account/settings/giveaways",
  927. dataType: "html",
  928. onload: function(data){
  929. var $header = $(data.responseText).filter("header");
  930. var $page_outer = $(data.responseText).filter(".page__outer-wrap");
  931. var $footer_outer = $(data.responseText).filter(".footer__outer-wrap");
  932.  
  933. $page_outer.find("form").remove();
  934. $page_outer.find(".sidebar__navigation .is-selected").removeClass("is-selected").find("a i").remove();
  935. var $sidebar_item = $('<li class="sidebar__navigation__item is-selected">\
  936. <a class="sidebar__navigation__item__link" href="/sg-game-tags">\
  937. <i class="fa fa-caret-right"></i>\
  938. <div class="sidebar__navigation__item__name">SG Game Tags</div>\
  939. <div class="sidebar__navigation__item__underline"></div>\
  940. </a>\
  941. </li>');
  942. $($page_outer.find(".sidebar__navigation")[2]).append($sidebar_item);
  943.  
  944. $("body").append($header).append($page_outer).append($footer_outer);
  945. $(".page__heading").after($('<div class="form__rows"></div>'));
  946. $(".page__heading__breadcrumbs").html('<a href="/sg-game-tags">SG Game Tags Setting</a>');
  947.  
  948. initTagPositionSetting();
  949. initTagOnOffSetting();
  950. initTagColorSetting();
  951. changeCBColor();
  952. AddShortcutToSettingPage();
  953. },
  954. ontimeout: function()
  955. {
  956. console.log("timeout");
  957. }
  958. });
  959. }
  960.  
  961. function initTagPositionSetting()
  962. {
  963. var no = $(".form__heading").length + 1;
  964. var CheckIcon = '<i class="form__checkbox__default fa fa-circle-o"></i><i class="form__checkbox__hover fa fa-circle"></i><i class="form__checkbox__selected fa fa-check-circle"></i>';
  965. var $form__row = $('<div class="form__row"></div>');
  966.  
  967. var $form__heading = $('<div class="form__heading"></div>');
  968. $form__heading
  969. .append('<div class="form__heading__number">' + no + '.</div>')
  970. .append('<div class="form__heading__text" title="This setting doesn\'t affect performance, only visual change."> Tags Style </div>');
  971.  
  972. var $form__row__indent = $('<div class="form__row__indent"></div>');
  973. var $form__checkbox_1 = createCheckBox("form__checkbox", CheckIcon + "(Original) Full Text tags below game title", cbTagStyle == 1);
  974. var $form__checkbox_2 = createCheckBox("form__checkbox", CheckIcon + "(Minimalist) One letter tags beside game title", cbTagStyle == 2);
  975.  
  976. $form__checkbox_1.attr("title", 'The tags will display "Trading Cards", "Bundled", etc. This option will increase page height.');
  977. $form__checkbox_2.attr("title", 'The tags will just display first letter. "Trading Cards" becomes "T", "Bundled" becomes "B", etc.');
  978.  
  979. $form__checkbox_1.click(function()
  980. {
  981. cbTagStyle = 1;
  982. GM_setValue("cbTagStyle", 1);
  983. toggleMinimalist(false);
  984. $form__checkbox_2.removeClass("is-selected");
  985. $form__checkbox_1.addClass("is-selected");
  986. });
  987. $form__checkbox_2.click(function()
  988. {
  989. cbTagStyle = 2;
  990. GM_setValue("cbTagStyle", 2);
  991. toggleMinimalist();
  992. $form__checkbox_1.removeClass("is-selected");
  993. $form__checkbox_2.addClass("is-selected");
  994. });
  995.  
  996. $form__row__indent.append($form__checkbox_1).append($form__checkbox_2);
  997.  
  998. $form__row.append($form__heading).append($form__row__indent);
  999. $(".form__rows").append($form__row);
  1000. }
  1001.  
  1002. function initTagOnOffSetting()
  1003. {
  1004. var no = $(".form__heading").length + 1;
  1005. var CheckIcon = '<i class="form__checkbox__default fa fa-circle-o"></i><i class="form__checkbox__hover fa fa-circle"></i><i class="form__checkbox__selected fa fa-check-circle"></i>';
  1006. var $form__row = $('<div class="form__row"></div>');
  1007.  
  1008. var $form__heading = $('<div class="form__heading"></div>');
  1009. $form__heading
  1010. .append('<div class="form__heading__number">' + no + '.</div>')
  1011. .append('<div class="form__heading__text" title="If you have performance issues, try disable tags you don\'t need"> Enable/Disable Tags </div>');
  1012.  
  1013. var $form__checkbox_1 = createCheckBox("my__checkbox", CheckIcon + pBundle.text, cbBundled);
  1014. var $form__checkbox_2 = createCheckBox("my__checkbox", CheckIcon + pCard.text, cbCards);
  1015. var $form__checkbox_3 = createCheckBox("my__checkbox", CheckIcon + pAchievement.text, cbAchievement);
  1016. var $form__checkbox_4 = createCheckBox("my__checkbox", CheckIcon + pHidden.text, cbHidden);
  1017. var $form__checkbox_5 = createCheckBox("my__checkbox", CheckIcon + pWishlist.text, cbWishlist);
  1018. var $form__checkbox_6 = createCheckBox("my__checkbox", CheckIcon + pLinux.text, cbLinux);
  1019. var $form__checkbox_7 = createCheckBox("my__checkbox", CheckIcon + pMac.text, cbMac);
  1020. var $form__checkbox_8 = createCheckBox("my__checkbox", CheckIcon + pEarly.text, cbEarly);
  1021. var $form__checkbox_9 = createCheckBox("my__checkbox", CheckIcon + pOwned.text, cbOwned);
  1022. var $form__checkbox10 = createCheckBox("my__checkbox", CheckIcon + pIgnored.text, cbIgnored);
  1023. var $form__checkbox11 = $('<div class="my__checkbox is-disabled">' + CheckIcon + 'Not-Bundled</div>');
  1024. if(cbBundled == 2)
  1025. {
  1026. $form__checkbox11.addClass("is-selected").removeClass("is-disabled");
  1027. $form__checkbox_1.addClass("is-disabled").removeClass("is-selected");
  1028. }
  1029.  
  1030. $form__checkbox_1.click(function(){
  1031. if(cbBundled == 1){
  1032. $form__checkbox_1.removeClass("is-selected").addClass("is-disabled");
  1033. cbBundled = 0;
  1034. }
  1035. else{
  1036. $form__checkbox_1.removeClass("is-disabled").addClass("is-selected");
  1037. $form__checkbox11.removeClass("is-selected").addClass("is-disabled");
  1038. if(cbTagStyle == 1)
  1039. $("."+pBundle.class).html(pBundle.text);
  1040. else if(cbTagStyle == 2)
  1041. $("."+pBundle.class).html(pBundle.min);
  1042. cbBundled = 1;
  1043. }
  1044. changeCBColor();
  1045. GM_setValue("cbBundled", cbBundled);
  1046. });
  1047. $form__checkbox11.click(function(){
  1048. if(cbBundled == 2){
  1049. $form__checkbox11.removeClass("is-selected").addClass("is-disabled");
  1050. cbBundled = 0;
  1051. }
  1052. else{
  1053. $form__checkbox_1.removeClass("is-selected").addClass("is-disabled");
  1054. $form__checkbox11.removeClass("is-disabled").addClass("is-selected");
  1055. if(cbTagStyle == 1)
  1056. $("."+pBundle.class).html(pBundle.text2);
  1057. else if(cbTagStyle == 2)
  1058. $("."+pBundle.class).html(pBundle.min2);
  1059. cbBundled = 2;
  1060. }
  1061. changeCBColor();
  1062. GM_setValue("cbBundled", cbBundled);
  1063. });
  1064.  
  1065. $form__checkbox_2.click(function(){toggleCBTags($form__checkbox_2, "cbCards");});
  1066. $form__checkbox_3.click(function(){toggleCBTags($form__checkbox_3, "cbAchievement");});
  1067. $form__checkbox_4.click(function(){toggleCBTags($form__checkbox_4, "cbHidden");});
  1068. $form__checkbox_5.click(function(){toggleCBTags($form__checkbox_5, "cbWishlist");});
  1069. $form__checkbox_6.click(function(){toggleCBTags($form__checkbox_6, "cbLinux");});
  1070. $form__checkbox_7.click(function(){toggleCBTags($form__checkbox_7, "cbMac");});
  1071. $form__checkbox_8.click(function(){toggleCBTags($form__checkbox_8, "cbEarly");});
  1072. $form__checkbox_9.click(function(){toggleCBTags($form__checkbox_9, "cbOwned");});
  1073. $form__checkbox10.click(function(){toggleCBTags($form__checkbox10, "cbIgnored");});
  1074.  
  1075. var $form__row__indent = $('<div class="form__row__indent"></div>');
  1076. $form__row__indent
  1077. .append($form__checkbox_1).append($form__checkbox11)
  1078. .append($form__checkbox_2)
  1079. .append($form__checkbox_3)
  1080. .append($form__checkbox_4)
  1081. .append($form__checkbox_5)
  1082. .append($form__checkbox_6)
  1083. .append($form__checkbox_7)
  1084. .append($form__checkbox_8)
  1085. .append($form__checkbox_9)
  1086. .append($form__checkbox10);
  1087.  
  1088. $form__row.append($form__heading).append($form__row__indent);
  1089. $(".form__rows").append($form__row);
  1090. }
  1091.  
  1092. function createCheckBox(_class, _html, cbValue)
  1093. {
  1094. var $cb = $('<div class="' + _class + '">' + _html + '</div>');
  1095. if(cbValue)
  1096. $cb.addClass("is-selected");
  1097. else
  1098. $cb.addClass("is-disabled");
  1099. return $cb;
  1100. }
  1101.  
  1102. function toggleCBTags(cbElems, cbName)
  1103. {
  1104. var cbValue;
  1105. if(cbName == "cbCards")
  1106. cbValue = cbCards = !cbCards;
  1107. else if(cbName == "cbAchievement")
  1108. cbValue = cbAchievement = !cbAchievement;
  1109. else if(cbName == "cbBundled")
  1110. cbValue = cbBundled = !cbBundled;
  1111. else if(cbName == "cbHidden")
  1112. cbValue = cbHidden = !cbHidden;
  1113. else if(cbName == "cbWishlist")
  1114. cbValue = cbWishlist = !cbWishlist;
  1115. else if(cbName == "cbLinux")
  1116. cbValue = cbLinux = !cbLinux;
  1117. else if(cbName == "cbMac")
  1118. cbValue = cbMac = !cbMac;
  1119. else if(cbName == "cbEarly")
  1120. cbValue = cbEarly = !cbEarly;
  1121. else if(cbName == "cbOwned")
  1122. cbValue = cbOwned = !cbOwned;
  1123. else if(cbName == "cbIgnored")
  1124. cbValue = cbIgnored = !cbIgnored;
  1125.  
  1126. if(cbValue)
  1127. $(cbElems).removeClass("is-disabled").addClass("is-selected");
  1128. else
  1129. $(cbElems).removeClass("is-selected").addClass("is-disabled");
  1130.  
  1131. GM_setValue(cbName, cbValue);
  1132. changeCBColor();
  1133. }
  1134.  
  1135. function changeCBColor()
  1136. {
  1137. var colorCBDisabled = $(".form__checkbox.is-disabled").css("color");
  1138. var colorCBSelected = $(".form__checkbox.is-selected").css("color");
  1139. $(".my__checkbox.is-disabled").css("color", colorCBDisabled);
  1140. $(".my__checkbox.is-selected").css("color", colorCBSelected);
  1141. }
  1142.  
  1143. function initRowColorPicker(name, tag)
  1144. {
  1145. var $row = $('<div class="row"></div');
  1146. var $cp1 = $('<input type="text" class="colorpicker" id="' + name + '-1"/>');
  1147. var $cp2 = $('<input type="text" class="colorpicker" id="' + name + '-2"/>');
  1148. $row.append($cp1).append($cp2)
  1149. .append('<div class="markdown"><a class="default_' + name + '">Default</a></div>')
  1150. .append('<div class="preview-tags"><a class="tags ' + tag.class + '" style="display: inline-block;">' + tag.text + '</a></div>');
  1151.  
  1152. initColorpicker($cp1, GM_getValue(name+"-1", tag.color1), tag.class, "background-color", name+"-1");
  1153. initColorpicker($cp2, GM_getValue(name+"-2", tag.color2), tag.class, "color", name+"-2");
  1154.  
  1155. $row.find("a").click(function(){clickDefaultColor(name, tag);});
  1156. return $row;
  1157. }
  1158.  
  1159. function initTagColorSetting()
  1160. {
  1161. var no = $(".form__heading").length + 1;
  1162. var $form__row = $('<div class="form__row"></div>');
  1163. var $form__heading = $('<div class="form__heading"></div>');
  1164. $form__heading
  1165. .append('<div class="form__heading__number">' + no + '.</div>')
  1166. .append('<div class="form__heading__text" title="This setting doesn\'t affect performance, only visual change.">Customize tags color</div>');
  1167.  
  1168. var $form__row__indent = $('<div class="form__row__indent"></div>');
  1169. $form__row__indent
  1170. .append(initRowColorPicker("bundle", pBundle))
  1171. .append(initRowColorPicker("card", pCard))
  1172. .append(initRowColorPicker("achievement", pAchievement))
  1173. .append(initRowColorPicker("wishlist", pWishlist))
  1174. .append(initRowColorPicker("hidden", pHidden))
  1175. .append(initRowColorPicker("linux", pLinux))
  1176. .append(initRowColorPicker("mac", pMac))
  1177. .append(initRowColorPicker("early", pEarly))
  1178. .append(initRowColorPicker("owned", pOwned))
  1179. .append(initRowColorPicker("ignored", pIgnored));
  1180.  
  1181. $form__row.append($form__heading).append($form__row__indent);
  1182.  
  1183. $(".form__rows").append($form__row);
  1184.  
  1185. if(cbBundled == 2)
  1186. $(".tags_bundle").html(pBundle.text2);
  1187. if(cbTagStyle == 2) // change tags if minimalist selected
  1188. toggleMinimalist();
  1189. }
  1190.  
  1191. function initColorpicker($cp, currentColor, tag, property, GMsetValue)
  1192. {
  1193. $cp.spectrum(
  1194. {
  1195. showInput: true, // show color code and lets user input color code
  1196. showInitial: true, //show previous color to compare with new color
  1197. showPalette: true,
  1198. showSelectionPalette: true,
  1199. preferredFormat: "hex", //display hex code
  1200. localStorageKey: "spectrum.sggametags",
  1201. maxSelectionSize: 8,
  1202. palette: [
  1203. [pBundle.color1, pCard.color1, pAchievement.color1, pWishlist.color1, pHidden.color1, pLinux.color1, pMac.color1, pEarly.color1, pOwned.color1, pIgnored.color1],
  1204. ["#000","#444","#666","#999","#ccc","#eee","#f3f3f3","#fff"],
  1205. ["#f00","#f90","#ff0","#0f0","#0ff","#00f","#90f","#f0f"],
  1206. ["#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#cfe2f3","#d9d2e9","#ead1dc"],
  1207. ["#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#9fc5e8","#b4a7d6","#d5a6bd"],
  1208. ["#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6fa8dc","#8e7cc3","#c27ba0"],
  1209. ["#c00","#e69138","#f1c232","#6aa84f","#45818e","#3d85c6","#674ea7","#a64d79"],
  1210. ["#900","#b45f06","#bf9000","#38761d","#134f5c","#0b5394","#351c75","#741b47"],
  1211. ["#600","#783f04","#7f6000","#274e13","#0c343d","#073763","#20124d","#4c1130"]
  1212. ],
  1213. color:currentColor,
  1214. move: function(color){
  1215. $("."+tag).css(property, color.toHexString());
  1216. },
  1217. change: function(color){
  1218. $("."+tag).css(property, color.toHexString());
  1219. },
  1220. hide: function(color){
  1221. GM_setValue(GMsetValue, color.toHexString());
  1222. }
  1223. });
  1224. }
  1225.  
  1226. function clickDefaultColor(name, tagprop)
  1227. {
  1228. GM_setValue(name+"-1", tagprop.color1);
  1229. GM_setValue(name+"-2", tagprop.color2);
  1230. $("."+tagprop.class).css("background-color", tagprop.color1).css("color", tagprop.color2);
  1231. $("#"+name+"-1").spectrum("set", tagprop.color1);
  1232. $("#"+name+"-2").spectrum("set", tagprop.color2);
  1233. }
  1234.  
  1235. function toggleMinimalist(minimalist = true)
  1236. {
  1237. $("."+pBundle.class).text(minimalist ? pBundle.min : pBundle.text);
  1238. $("."+pCard.class).text(minimalist ? pCard.min : pCard.text);
  1239. $("."+pAchievement.class).text(minimalist ? pAchievement.min : pAchievement.text);
  1240. $("."+pWishlist.class).text(minimalist ? pWishlist.min : pWishlist.text);
  1241. $("."+pLinux.class).text(minimalist ? pLinux.min : pLinux.text);
  1242. $("."+pMac.class).text(minimalist ? pMac.min : pMac.text);
  1243. $("."+pEarly.class).text(minimalist ? pEarly.min : pEarly.text);
  1244. $("."+pHidden.class).text(minimalist ? pHidden.min : pHidden.text);
  1245. $("."+pOwned.class).text(minimalist ? pOwned.min : pOwned.text);
  1246. $("."+pIgnored.class).text(minimalist ? pIgnored.min : pIgnored.text);
  1247.  
  1248. if(cbBundled == 2)
  1249. $("."+pBundle.class).text(minimalist ? pBundle.min2 : pBundle.text2);
  1250. }
  1251.  
  1252. // ==================================================================================================
  1253. function AddShortcutToSettingPage()
  1254. {
  1255. var shortcut = '\
  1256. <a class="nav__row sggt_shortcut" href="/sg-game-tags"> \
  1257. <i class="icon-yellow fa fa-fw fa-tag"></i> \
  1258. <div class="nav__row__summary"> \
  1259. <p class="nav__row__summary__name">SG Game Tags Setting</p> \
  1260. <p class="nav__row__summary__description">Open SG Game Tags setting page</span>.</p> \
  1261. </div> \
  1262. </a>';
  1263. var $dropdown = $(".nav__right-container .nav__absolute-dropdown .nav__row");
  1264. $($dropdown[2]).before(shortcut); // just before logout button
  1265. }