SG Game Tags

Shows some tags of the game in Steamgifts.

目前為 2016-04-26 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name SG Game Tags
  3. // @namespace https://steamcommunity.com/id/Ruphine/
  4. // @version 2.11.5
  5. // @description Shows some tags of the game in Steamgifts.
  6. // @author Ruphine
  7.  
  8. // @include http://www.steamgifts.com/*
  9. // @include https://www.steamgifts.com/*
  10. // @connect steampowered.com
  11. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
  12. // @grant GM_deleteValue
  13. // @grant GM_getValue
  14. // @grant GM_listValues
  15. // @grant GM_setValue
  16. // @grant GM_xmlhttpRequest
  17. // ==/UserScript==
  18.  
  19. /* CSS */
  20. var myCSS;
  21. myCSS = '<style> \
  22. .tags { \
  23. color: #FFFFFF; \
  24. text-decoration: none; \
  25. border-radius: 4px; \
  26. padding-top: 2px; \
  27. padding-bottom: 2px; \
  28. padding-left: 5px; \
  29. padding-right: 5px; \
  30. font-size: 8pt; \
  31. margin-right: 3px; \
  32. margin-bottom: 3px; \
  33. margin-top: 3px; \
  34. text-shadow: none; \
  35. display: none; \
  36. } \
  37. .tags-green { background-color: #3AA435; } \
  38. .tags-red { background-color: #E9202A; } \
  39. .tags-blue { background-color: #305AC9; } \
  40. .tags-purple { background-color: #6600CC; } \
  41. .tags-brown { background-color: #A0522D; } \
  42. .tags-linux { background-color: #e67300; } \
  43. .tags-mac { background-color: #777;} \
  44. .my__checkbox { \
  45. cursor:pointer; \
  46. padding:7px 0 \
  47. } \
  48. .my__checkbox i { \
  49. margin-right:7px \
  50. } \
  51. .my__checkbox:not(:last-of-type) { \
  52. border-bottom:1px dotted #d2d6e0 \
  53. } \
  54. .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 { \
  55. display:none \
  56. } \
  57. </style>';
  58.  
  59. $("head").append(myCSS);
  60.  
  61.  
  62. /* Constant Variables */
  63. const linkCard = "http://www.steamcardexchange.net/index.php?inventorygame-appid-";
  64. const linkAchievement = "http://steamcommunity.com/stats/"; // 424280/achievements/";
  65. const linkBundle = "https://www.steamgifts.com/bundle-games/search?q=";
  66. const linkHidden = "https://www.steamgifts.com/account/settings/giveaways/filters/search?q=";
  67. const linkWishlist = "https://www.steamgifts.com/account/steam/wishlist/search?q=";
  68.  
  69. const linkGameAPI = "http://store.steampowered.com/api/appdetails?filters=categories,platforms&appids=";
  70. const linkPackAPI = "http://store.steampowered.com/api/packagedetails?filters=categories&packageids=";
  71.  
  72. const ClassCard = "tags tags-green";
  73. const TitleCard = "This game has trading cards";
  74. const TextCard = "Trading Cards";
  75.  
  76. const ClassBundle = "tags tags-red";
  77. const TitleBundle = "This game is marked as bundled by Steamgifts";
  78. const TextBundle = "Bundled";
  79.  
  80. const ClassAchievement = "tags tags-blue";
  81. const TitleAchievement = "This game has steam achievements";
  82. const TextAchievement = "Achievements";
  83.  
  84. const ClassHidden = "tags tags-brown";
  85. const TitleHidden = "This game is in your filter list";
  86. const TextHidden = "Hidden";
  87.  
  88. const ClassWishlist = "tags tags-purple";
  89. const TitleWishlist = "This game is in your Steam wishlist";
  90. const TextWishlist = "Wishlist";
  91.  
  92. const ClassLinux = "tags tags-linux";
  93. const TitleLinux = "Linux supported";
  94. const TextLinux = "Linux";
  95.  
  96. const ClassMac = "tags tags-mac";
  97. const TitleMac = "Mac supported";
  98. const TextMac = "Mac";
  99.  
  100. var cbCards = GM_getValue("cbCards", true);
  101. var cbAchievement = GM_getValue("cbAchievement", true);
  102. var cbBundled = GM_getValue("cbBundled", true);
  103. var cbHidden = GM_getValue("cbHidden", true);
  104. var cbWishlist = GM_getValue("cbWishlist", true);
  105. var cbLinux = GM_getValue("cbLinux", true);
  106. var cbMac = GM_getValue("cbMac", true);
  107.  
  108. main();
  109.  
  110. function main()
  111. {
  112. var currLoc = window.location.href.split("/");
  113.  
  114. // shows trading card tag in featured game (header)
  115. if($(".featured__inner-wrap").length == 1) //exclude page without featured inner wrap
  116. {
  117. var url;
  118. if(currLoc[3] == "giveaway") //giveaway page
  119. url = $(".featured__inner-wrap a")[0].href;
  120. else if(currLoc[3] != "user" && currLoc[3] != "group") //homepage
  121. url = $(".featured__inner-wrap a img")[0].src;
  122.  
  123. if (url != null) //for game without appID e.g Humble Indie Bundle
  124. {
  125. var ID = getAppIDfromLink(url);
  126. var Name = $(".featured__heading__medium").text().substring(0,30);
  127. Name = Name.replace("+", "%2B").replace("[NEW] ", "").replace("[FREE] ", ""); //remove [NEW] and [FREE] to make it work with ext SG
  128. var target = $(".featured__heading");
  129.  
  130. var tagCard = createTag(ClassCard, TitleCard, TextCard, linkCard+ID, target);
  131. var tagAchievement = createTag(ClassAchievement, TitleAchievement, TextAchievement, linkAchievement+ID+"/achievements/", tagCard);
  132. var tagBundle = createTag(ClassBundle, TitleBundle, TextBundle, linkBundle+Name, tagAchievement);
  133. var tagHidden = createTag(ClassHidden, TitleHidden, TextHidden, linkHidden+Name, tagBundle);
  134. var tagWishlist = createTag(ClassWishlist, TitleWishlist, TextWishlist, linkWishlist+Name, tagHidden);
  135. var tagLinux = createTag(ClassLinux, TitleLinux, TextLinux, url, tagWishlist);
  136. var tagMac = createTag(ClassMac, TitleMac, TextMac, url, tagLinux);
  137.  
  138. if(isApp(url))
  139. {
  140. getSteamCategories(ID, tagCard, tagAchievement, tagLinux, tagMac);
  141. }
  142. else if(isPackage(url))
  143. {
  144. tagCard.setAttribute("href", url);
  145. tagAchievement.setAttribute("href", url);
  146. getSteamCategoriesFromPackage(ID, tagCard, tagAchievement, tagLinux, tagMac);
  147. }
  148.  
  149. getBundleStatus(ID, Name, tagBundle);
  150.  
  151. if(currLoc[3] == "giveaway") //only trigger inside giveaway page, no need for homepage
  152. {
  153. getHiddenStatus(ID, Name, tagHidden);
  154. getWishlistStatus(ID, Name, tagWishlist);
  155. }
  156. }
  157. }
  158. else if(currLoc[3] == "giveaways" && currLoc[4] == "new") // http://www.steamgifts.com/giveaways/new
  159. {
  160. $(".js__autocomplete-data").on("DOMNodeInserted", NewGiveawayDivUpdated);
  161. }
  162.  
  163. // http://www.steamgifts.com/giveaways/*
  164. // http://www.steamgifts.com/sales/*
  165. // http://www.steamgifts.com/account/settings/giveaways/filters
  166. // http://www.steamgifts.com/account/steam/*
  167. else if((currLoc[3] == "giveaways" && !(/search*/.test(currLoc[4]))) || currLoc[6] == "filters" || currLoc[3] == "sales" || currLoc[4] == "steam")
  168. {
  169. $(".table__row-inner-wrap").each(function(index, element)
  170. {
  171.  
  172. var Name = $(element).find(".table__column__heading").text().substring(0,30);
  173. Name = Name.replace("+", "%2B").replace("[NEW] ", "").replace("[FREE] ", ""); //remove [NEW] and [FREE] to make it work with ext SG
  174. var target = $(element).find(".table__column--width-fill > :first-child");
  175.  
  176. //because sales don't use <p> thus tags will appears in line with title
  177. if(currLoc[3] == "sales") target.css("display", "block");
  178.  
  179. var url;
  180. if(currLoc[6] == "filters")
  181. url = $(element).find("a.table__column__secondary-link").text();
  182. else
  183. url = $($(element).find(".global__image-inner-wrap")[0]).css('background-image');
  184.  
  185. if(url != null) //if can get app ID from image
  186. {
  187. url = url.replace('url(', '').replace(')', '');
  188. var ID = getAppIDfromLink(url);
  189.  
  190. var tagCard = createTag(ClassCard, TitleCard, TextCard, linkCard+ID, target);
  191. var tagAchievement = createTag(ClassAchievement, TitleAchievement, TextAchievement, linkAchievement+ID+"/achievements/", tagCard);
  192. var tagBundle = createTag(ClassBundle, TitleBundle, TextBundle, linkBundle+Name, tagAchievement);
  193. var tagLinux = createTag(ClassLinux, TitleLinux, TextLinux, url, tagBundle);
  194. var tagMac = createTag(ClassMac, TitleMac, TextMac, url, tagLinux);
  195.  
  196. if(isApp(url))
  197. {
  198. getSteamCategories(ID, tagCard, tagAchievement, tagLinux, tagMac);
  199. }
  200. else if(isPackage(url))
  201. {
  202. tagCard.setAttribute("href", url);
  203. tagAchievement.setAttribute("href", url);
  204. getSteamCategoriesFromPackage(ID, tagCard, tagAchievement, tagLinux, tagMac);
  205. }
  206.  
  207. getBundleStatus(ID, Name, tagBundle);
  208. }
  209. });
  210. }
  211.  
  212. //Giveaway Page
  213. ProcessGiveawayListPage($(".giveaway__row-inner-wrap"));
  214.  
  215. // handles element added later by endless scroll
  216. $(document).on("DOMNodeInserted", ".widget-container", function(e) {
  217. ProcessGiveawayListPage($(e.target).find(".giveaway__row-inner-wrap"));
  218. });
  219.  
  220. if(window.location.href == "https://www.steamgifts.com/account/settings/giveaways")
  221. initSetting();
  222. }
  223.  
  224. // http://www.steamgifts.com/
  225. // http://www.steamgifts.com/giveaways/search*
  226. // http://www.steamgifts.com/user/*
  227. // http://www.steamgifts.com/group/*
  228. function ProcessGiveawayListPage(scope)
  229. {
  230. $(scope).each(function(index, element)
  231. {
  232. var url = $(element).find("a.giveaway__icon").attr("href");
  233. if(url != null)
  234. {
  235. var ID = getAppIDfromLink(url);
  236.  
  237. var Name = $(element).find(".giveaway__heading__name").text().substring(0,30);
  238. Name = Name.replace("+", "%2B").replace("[NEW] ", "").replace("[FREE] ", ""); //remove [NEW] and [FREE] to make it work with ext SG
  239. var target = $(element).find(".giveaway__heading");
  240.  
  241. var tagCard = createTag(ClassCard, TitleCard, TextCard, linkCard+ID, target);
  242. var tagAchievement = createTag(ClassAchievement, TitleAchievement, TextAchievement, linkAchievement+ID+"/achievements/", tagCard);
  243. var tagBundle = createTag(ClassBundle, TitleBundle, TextBundle, linkBundle+Name, tagAchievement);
  244. var tagLinux = createTag(ClassLinux, TitleLinux, TextLinux, url, tagBundle);
  245. var tagMac = createTag(ClassMac, TitleMac, TextMac, url, tagLinux);
  246.  
  247. if(isApp(url))
  248. {
  249. getSteamCategories(ID, tagCard, tagAchievement, tagLinux, tagMac);
  250. }
  251. else if(isPackage(url))
  252. {
  253. tagCard.setAttribute("href", url);
  254. tagAchievement.setAttribute("href", url);
  255. getSteamCategoriesFromPackage(ID, tagCard, tagAchievement, tagLinux, tagMac);
  256. }
  257.  
  258. getBundleStatus(ID, Name, tagBundle);
  259. }
  260. });
  261. }
  262.  
  263. function createTag(_class, title, text, href, divTarget)
  264. {
  265. var tag = document.createElement("a");
  266. tag.setAttribute("id", "tags");
  267. tag.setAttribute("target", "_blank");
  268. tag.setAttribute("class", _class);
  269. tag.setAttribute("title", title);
  270. tag.setAttribute("href", href);
  271. tag.innerHTML = text;
  272.  
  273. $(divTarget).after(tag);
  274. return tag;
  275. }
  276.  
  277. function displayElems(elems)
  278. {
  279. $(elems).css("display", "inline-block");
  280. }
  281.  
  282. function getSteamCategories(appID, tagCard, tagAchievement, tagLinux, tagMac)
  283. {
  284. var jsonCards = GM_getValue("cards-" + appID, "");
  285. var jsonAchievement = GM_getValue("achievements-" + appID, "");
  286. var jsonLinux = GM_getValue("linux-" + appID, "");
  287. var jsonMac = GM_getValue("mac-" + appID, "");
  288.  
  289. var reqCard = needRequest(jsonCards);
  290. var reqAchievement = needRequest(jsonAchievement);
  291. var reqLinux = needRequest(jsonLinux);
  292. var reqMac = needRequest(jsonMac);
  293.  
  294. if(!reqCard && cbCards) // if app card is saved
  295. {
  296. if(JSON.parse(jsonCards).val)
  297. displayElems(tagCard);
  298. }
  299. if(!reqAchievement && cbAchievement) // if app achievement is saved
  300. {
  301. if(JSON.parse(jsonAchievement).val)
  302. displayElems(tagAchievement);
  303. }
  304. if(!reqLinux && cbLinux) // if app linux is saved
  305. {
  306. if(JSON.parse(jsonLinux).val)
  307. displayElems(tagLinux);
  308. }
  309. if(!reqMac && cbMac) // if app mac is saved
  310. {
  311. if(JSON.parse(jsonMac).val)
  312. displayElems(tagMac);
  313. }
  314.  
  315. if((reqCard && cbCards) || (reqAchievement && cbAchievement) || (reqLinux && cbLinux) || (reqMac && cbMac))
  316. {
  317. console.log("request steam " + appID);
  318. GM_xmlhttpRequest({
  319. method: "GET",
  320. timeout: 10000,
  321. url: linkGameAPI+appID,
  322. onload: function(data)
  323. {
  324. var obj = JSON.parse(data.responseText)[appID].data;
  325. if(obj == null)
  326. {
  327. console.log("apps " + appID + " does not have store page or does not exist");
  328. saveData("cards-" + appID, false);
  329. saveData("achievements-" + appID, false);
  330. saveData("linux-" + appID, false);
  331. saveData("mac-" + appID, false);
  332. }
  333. else
  334. {
  335. // get steam apps categories : achievement, trading cards, etc
  336. var categories = obj.categories;
  337. flagCard = false;
  338. flagAchievement = false;
  339. if(categories != null)
  340. {
  341. for(i=0; i<categories.length; i++)
  342. {
  343. if(categories[i].id == "29" && cbCards)
  344. {
  345. displayElems(tagCard);
  346. saveData("cards-" + appID, true);
  347. flagCard = true;
  348. }
  349. if(categories[i].id == "22" && cbAchievement)
  350. {
  351. displayElems(tagAchievement);
  352. saveData("achievements-" + appID, true);
  353. flagAchievement = true;
  354. }
  355. }
  356. }
  357. else
  358. console.log("apps " + appID + " does not have categories");
  359.  
  360. if(reqCard && !flagCard)
  361. saveData("cards-" + appID, false);
  362. if(reqAchievement && !flagAchievement)
  363. saveData("achievements-" + appID, false);
  364.  
  365. // get steam apps platforms: linux: boolean, mac: boolean
  366. var platforms = obj.platforms;
  367. if(platforms.linux == true && cbLinux)
  368. {
  369. displayElems(tagLinux);
  370. saveData("linux-" + appID, true);
  371. }
  372. else
  373. saveData("linux-" + appID, false);
  374. if(platforms.mac == true && cbMac)
  375. {
  376. displayElems(tagMac);
  377. saveData("mac-" + appID, true);
  378. }
  379. else
  380. saveData("mac-" + appID, false);
  381. }
  382. }
  383. });
  384. }
  385. }
  386.  
  387. function getBundleStatus(appID, appName, elems)
  388. {
  389. if(cbBundled)
  390. {
  391. var jsonBundle = GM_getValue("bundled-" + appID, "");
  392. if(!needRequest(jsonBundle))
  393. {
  394. if(JSON.parse(jsonBundle).val)
  395. displayElems(elems);
  396. }
  397. else
  398. {
  399. console.log("request bundle " + appID + " - " + appName);
  400. $.get( linkBundle+appName, function(data)
  401. {
  402. var gamesfound = $(data).find(".table__column__secondary-link");
  403. for(i=0; i<$(gamesfound).length; i++)
  404. {
  405. var url = $(gamesfound)[i].href;
  406. var ID = getAppIDfromLink(url);
  407.  
  408. if(appID == ID)
  409. {
  410. //TODO : Save appID + true ke local cache
  411. displayElems(elems);
  412. saveData("bundled-" + appID, true);
  413. return true; //exit function
  414. }
  415. }
  416. saveData("bundled-" + appID, false);
  417. });
  418. }
  419. }
  420. }
  421.  
  422. function getHiddenStatus(appID, appName, elems)
  423. {
  424. if(cbHidden)
  425. {
  426. console.log("request hidden " + appID + " - " + appName);
  427. $.get(linkHidden+appName, function(data)
  428. {
  429. var gamesfound = $(data).find("a.table__column__secondary-link");
  430. for(i=0; i<$(gamesfound).length; i++)
  431. {
  432. var url = $(gamesfound)[i].href;
  433. var ID = getAppIDfromLink(url);
  434. if(appID == ID)
  435. {
  436. //TODO : Save appID + true ke local cache
  437. displayElems(elems);
  438. return true; //exit function
  439. }
  440. }
  441. });
  442. }
  443. }
  444.  
  445. function getWishlistStatus(appID, appName, elems)
  446. {
  447. if(cbWishlist)
  448. {
  449. console.log("request wishlist " + appID + " - " + appName);
  450. $.get(linkWishlist+appName, function(data)
  451. {
  452. var gamesfound = $(data).find("a.table__column__secondary-link");
  453. for(i=0; i<$(gamesfound).length; i++)
  454. {
  455. var url = $(gamesfound)[i].href;
  456. var ID = getAppIDfromLink(url);
  457. if(appID == ID)
  458. {
  459. //TODO : Save appID + true ke local cache
  460. displayElems(elems);
  461. return true; //exit function
  462. }
  463. }
  464. });
  465. }
  466. }
  467.  
  468. function getSteamCategoriesFromPackage(appID, tagCard, tagAchievement, tagLinux, tagMac)
  469. {
  470. if(cbCards || cbAchievement)
  471. {
  472. //TODO: Check if the game is saved, if no then request to steam
  473. GM_xmlhttpRequest({
  474. method: "GET",
  475. timeout: 10000,
  476. url: linkPackAPI+appID,
  477. onload: function(data)
  478. {
  479. var IDs = JSON.parse(data.responseText)[appID].data;
  480. if(IDs == null)
  481. {
  482. console.log("package " + appID + " does not exist");
  483. saveData("cards-" + appID, false);
  484. saveData("achievements-" + appID, false);
  485. saveData("linux-" + appID, false);
  486. saveData("mac-" + appID, false);
  487. }
  488. else
  489. {
  490. IDs = IDs.apps;
  491. $.each(IDs, function(index)
  492. {
  493. getSteamCategories(IDs[index].id, tagCard, tagAchievement, tagLinux, tagMac);
  494. //TODO : Save appID + false + expire time ke local cache
  495. });
  496. }
  497. }
  498. });
  499. }
  500. }
  501.  
  502. function getAppIDfromLink(link)
  503. {
  504. var url = link.split("/");
  505. return url[url.length-2];
  506. }
  507.  
  508. function isApp(link)
  509. {
  510. var pattern = /\/app|apps\/0-9\//;
  511. return pattern.test(link);
  512. }
  513.  
  514. function isPackage(link)
  515. {
  516. var pattern = /\/sub|subs\/0-9\//;
  517. return pattern.test(link);
  518. }
  519.  
  520. function saveData(name, val)
  521. {
  522. var today = new Date().toJSON().slice(0,10);
  523. var data = {val:val, savedDate:today};
  524. GM_setValue(name, JSON.stringify(data));
  525. }
  526.  
  527. function needRequest(json)
  528. {
  529. if(json == "")
  530. return true;
  531. else
  532. {
  533. var obj = JSON.parse(json);
  534. if(obj.val)
  535. return false;
  536. else
  537. {
  538. var today = new Date().toJSON().slice(0,10);
  539. if(obj.savedDate == today)
  540. return false;
  541. else
  542. return true;
  543. }
  544. }
  545. }
  546.  
  547. function NewGiveawayDivUpdated(event)
  548. {
  549. if(event.type == "DOMNodeInserted") //show bundle tag for shown game
  550. {
  551. var gamesfound = $(".table__row-inner-wrap");
  552. $(".tags").remove();
  553. $(".table__row-inner-wrap").each(function(index, element)
  554. {
  555. var url = $(element).find("a.table__column__secondary-link").text();
  556. var ID = getAppIDfromLink(url);
  557. var Name = $(element).find(".table__column__heading").text();
  558. var Target = $(element).find(".table__column--width-fill");
  559.  
  560. $(".js__autocomplete-data").off("DOMNodeInserted");
  561. var tagBundle = createTag(ClassBundle, TitleBundle, TextBundle, linkBundle+Name, Target);
  562. $(tagBundle).css("float", "right");
  563. getBundleStatus(ID, Name, tagBundle);
  564. });
  565. if(gamesfound.length > 0)
  566. {
  567. $(".js__autocomplete-data").on("DOMNodeRemoved", NewGiveawayDivUpdated);
  568.  
  569. $(".table__row-inner-wrap").on("click", function(event)
  570. {
  571. var url = $(this).find("a.table__column__secondary-link").text();
  572. var ID = getAppIDfromLink(url);
  573. var Name = $(this).find(".table__column__heading").text();
  574. var Target = $(".js__autocomplete-name")[0];
  575. tagBundle = createTag(ClassBundle, TitleBundle, TextBundle, linkBundle+Name, Target);
  576. getBundleStatus(ID, Name, tagBundle);
  577. });
  578. }
  579. }
  580. else if(event.type == "DOMNodeRemoved")//show / remove tag of selected game
  581. {
  582. $(".js__autocomplete-data").off("DOMNodeRemoved");
  583. $(".table__row-inner-wrap").off("click");
  584. $(".js__autocomplete-data").on("DOMNodeInserted", NewGiveawayDivUpdated);
  585. }
  586. }
  587.  
  588. function initSetting()
  589. {
  590. var n = $(".form__heading").length + 1;
  591. 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>';
  592. var Color_picker = '<div><input id="textColor" type="color" value="" class="form-control" /></div>';
  593.  
  594. var form__row_1 = document.createElement("div");
  595. form__row_1.setAttribute("class", "form__row");
  596.  
  597. var form__heading_1 = document.createElement("div");
  598. form__heading_1.setAttribute("class", "form__heading");
  599.  
  600. var form__heading__number_1 = document.createElement("div");
  601. form__heading__number_1.setAttribute("class", "form__heading__number");
  602. form__heading__number_1.innerHTML = n + ".";
  603. n++;
  604.  
  605. var form__heading__text_1 = document.createElement("div");
  606. form__heading__text_1.setAttribute("class", "form__heading__text");
  607. form__heading__text_1.innerHTML = "[SG Game Tags] Which tags do you want to see?";
  608.  
  609. $(form__heading_1).append(form__heading__number_1).append(form__heading__text_1);
  610.  
  611. var form__row__indent_1 = document.createElement("div");
  612. form__row__indent_1.setAttribute("class", "form__row__indent");
  613.  
  614. var form__checkbox_1 = createCheckBox("my__checkbox", CheckIcon + "Trading Cards", cbCards);
  615. var form__checkbox_2 = createCheckBox("my__checkbox", CheckIcon + "Achievements", cbAchievement);
  616. var form__checkbox_3 = createCheckBox("my__checkbox", CheckIcon + "Bundled", cbBundled);
  617. var form__checkbox_4 = createCheckBox("my__checkbox", CheckIcon + "Hidden", cbHidden);
  618. var form__checkbox_5 = createCheckBox("my__checkbox", CheckIcon + "Wishlist", cbWishlist);
  619. var form__checkbox_6 = createCheckBox("my__checkbox", CheckIcon + "Linux", cbLinux);
  620. var form__checkbox_7 = createCheckBox("my__checkbox", CheckIcon + "Mac", cbMac);
  621.  
  622. $(form__checkbox_1).click(function(){toggleCBTags(form__checkbox_1, "cbCards");});
  623. $(form__checkbox_2).click(function(){toggleCBTags(form__checkbox_2, "cbAchievement");});
  624. $(form__checkbox_3).click(function(){toggleCBTags(form__checkbox_3, "cbBundled");});
  625. $(form__checkbox_4).click(function(){toggleCBTags(form__checkbox_4, "cbHidden");});
  626. $(form__checkbox_5).click(function(){toggleCBTags(form__checkbox_5, "cbWishlist");});
  627. $(form__checkbox_6).click(function(){toggleCBTags(form__checkbox_6, "cbLinux");});
  628. $(form__checkbox_7).click(function(){toggleCBTags(form__checkbox_7, "cbMac");});
  629.  
  630. $(form__row__indent_1)
  631. .append(form__checkbox_1)
  632. .append(form__checkbox_2)
  633. .append(form__checkbox_3)
  634. .append(form__checkbox_4)
  635. .append(form__checkbox_5)
  636. .append(form__checkbox_6)
  637. .append(form__checkbox_7);
  638.  
  639. $(form__row_1).append(form__heading_1).append(form__row__indent_1);
  640.  
  641. $(".js__submit-form").before(form__row_1);
  642.  
  643. var desc = document.createElement("div");
  644. desc.setAttribute("class", "form__input-description");
  645. desc.innerHTML = "No need to press Save Changes button. It is automatically saved when the value changed.";
  646. $(desc).appendTo([form__row__indent_1]);
  647.  
  648. changeCBColor();
  649. }
  650.  
  651. function createCheckBox(_class, _html, cbValue)
  652. {
  653. var cb = document.createElement("div");
  654. cb.setAttribute("class", _class);
  655. cb.innerHTML = _html;
  656. if(cbValue)
  657. $(cb).addClass("is-selected");
  658. else
  659. $(cb).addClass("is-disabled");
  660.  
  661. return cb;
  662. }
  663.  
  664. function toggleCBTags(cbElems, cbName)
  665. {
  666. var cbValue;
  667. if(cbName == "cbCards")
  668. {
  669. cbCards = !cbCards;
  670. cbValue = cbCards;
  671. }
  672. else if(cbName == "cbAchievement")
  673. {
  674. cbAchievement = !cbAchievement;
  675. cbValue = cbAchievement;
  676. }
  677. else if(cbName == "cbBundled")
  678. {
  679. cbBundled = !cbBundled;
  680. cbValue = cbBundled;
  681. }
  682. else if(cbName == "cbHidden")
  683. {
  684. cbHidden = !cbHidden;
  685. cbValue = cbHidden;
  686. }
  687. else if(cbName == "cbWishlist")
  688. {
  689. cbWishlist = !cbWishlist;
  690. cbValue = cbWishlist;
  691. }
  692. else if(cbName == "cbLinux")
  693. {
  694. cbLinux = !cbLinux;
  695. cbValue = cbLinux;
  696. }
  697. else if(cbName == "cbMac")
  698. {
  699. cbMac = !cbMac;
  700. cbValue = cbMac;
  701. }
  702.  
  703. GM_setValue(cbName, cbValue);
  704. if(cbValue)
  705. $(cbElems).removeClass("is-disabled").addClass("is-selected");
  706. else
  707. $(cbElems).removeClass("is-selected").addClass("is-disabled");
  708.  
  709. changeCBColor();
  710. }
  711.  
  712. function changeCBColor()
  713. {
  714. var colorCBDisabled = $(".form__checkbox.is-disabled").css("color");
  715. var colorCBSelected = $(".form__checkbox.is-selected").css("color");
  716.  
  717. $(".my__checkbox.is-disabled").css("color", colorCBDisabled);
  718. $(".my__checkbox.is-selected").css("color", colorCBSelected);
  719. }