SG Game Tags --- Sighery's mod

some tags of the game in Steamgifts.

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