SG Game Tags

Shows some tags of the game in Steamgifts.

目前为 2016-04-25 提交的版本。查看 最新版本

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