// ==UserScript==
// @name igg on steam and epic games
// @namespace my-web-site.cyleja1234.repl.co/
// @version 1.5
// @description open game on igg-games (other game store platforms coming soon!)
// @author Unknown81311#6616 (discord)
// @license GPL-3.0-or-later
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @match *store.steampowered.com/app/*
// @match https://www.epicgames.com/store/*
// @match https://www.origin.com/*
// @icon url https://store.steampowered.com/favicon.ico
// @icon https://store.steampowered.com/favicon.ico
// @copyright 2020, unknown81311 (https://openuserjs.org/users/unknown81311)
// @downloadURL none
// ==/UserScript==
var hostname = window.location.origin; //find curent domain
if ("https://store.steampowered.com" === window.location.origin) { //for steam
var name = $(".apphub_AppName").text(),
appName = name.replace(/ /g, "-").replace(/[^a-zA-Z0-9 -]/g, ""),
el1 = document.querySelector("#game_area_purchase > div.game_area_purchase_game_wrapper > div > div.game_purchase_action > div.game_purchase_action_bg > div.btn_addtocart"); //get game name
//set clone target elemnt
$(el1).clone().prependTo(".game_purchase_action").css({float: "right",display: "inline-block","background-color": "#000000",padding: "2px 2px 2px 0px"}); //clone originall button and add style
var link = "https://igg-games.com/" + appName + "-free-download.html",
target = "#game_area_purchase > div.game_area_purchase_game_wrapper > div > div.game_purchase_action > div.btn_addtocart > a"; //setlink
//set targettred elemnt
$(target).attr("href", link), //change link
$(target).attr("target", "_blank"), //redirect to new tab
$(target + " > span").text("Free"), //rename to free
$("#dlc_purchase_action > div:nth-child(1)").remove(), //remove bug
$("#game_area_purchase > div:nth-child(2) > div > div.game_purchase_action > div.btn_addtocart").remove()// remove bug
var iggSearchBaseUrl = "http://igg-games.com/?s=";
var search1 = appName.replace(/-/g, "+")
$(".btn_addtocart").append(' didn\'t work ');//add search
$("#game_area_purchase > div.game_area_purchase_game_wrapper > div > div.game_purchase_action > div.game_purchase_action_bg > div.btn_addtocart > a:nth-child(2)").remove();// remove bug
$("#dlc_purchase_action > div.btn_addtocart > a:nth-child(2)").remove();// remove bug
}
if ("https://www.epicgames.com" === window.location.origin) { //for epic games
var name2 = $("#dieselReactWrapper > div > div.css-igz6h5-AppPage__bodyContainer > main > div > nav.css-1v9fujt-PageNav__topNav-PageNav__desktopNav-PageNav__themed > div > nav > div > div.css-eizwrh-NavigationBar__contentPrimary > ul > li:nth-child(2) > a > h2 > span").text(); //get game name
var appName2 = name2.replace(/ /g, "-").replace(/[^a-zA-Z0-9 -]/g, ""); //replace space with "-" and "'"
var el2 = "#dieselReactWrapper > div > div.css-igz6h5-AppPage__bodyContainer > main > div > div > div.ProductDetails-wrapper_2d124844 > div > div.ProductDetailHeader-wrapper_e0846efc > div:nth-child(2) > div > div > div.Description-ctaWrapper_e8d00c38 > div > div > div > div.css-wgi9q7 > div >";
$("#dieselReactWrapper > div > div.css-igz6h5-AppPage__bodyContainer > main > div > div > div.ProductDetails-wrapper_2d124844 > div > div.ProductDetailHeader-wrapper_e0846efc > div:nth-child(2) > div > div > div.Description-ctaWrapper_e8d00c38 > div > div > div > div.css-wgi9q7 > div > button").clone().prependTo("#dieselReactWrapper > div > div.css-igz6h5-AppPage__bodyContainer > main > div > div > div.ProductDetails-wrapper_2d124844 > div > div.ProductDetailHeader-wrapper_e0846efc > div:nth-child(2) > div > div > div.Description-ctaWrapper_e8d00c38 > div > div > div > div.css-wgi9q7 > div"), $("#dieselReactWrapper > div > div.css-igz6h5-AppPage__bodyContainer > main > div > div > div.ProductDetails-wrapper_2d124844 > div > div.ProductDetailHeader-wrapper_e0846efc > div:nth-child(2) > div > div > div.Description-ctaWrapper_e8d00c38 > div > div > div > div.css-wgi9q7 > div > button:nth-child(1) > span > span").text("Free"), //rename to free
$("#dieselReactWrapper > div > div.css-igz6h5-AppPage__bodyContainer > main > div > div > div.ProductDetails-wrapper_2d124844 > div > div.ProductDetailHeader-wrapper_e0846efc > div:nth-child(2) > div > div > div.Description-ctaWrapper_e8d00c38 > div > div > div > div.css-wgi9q7 > div > button:nth-child(1)").removeAttr('disabled'); //enable button
var link2 = "https://igg-games.com/" + appName2 + "-free-download.html"; //setlink
$("#dieselReactWrapper > div > div.css-igz6h5-AppPage__bodyContainer > main > div > div > div.ProductDetails-wrapper_2d124844 > div > div.ProductDetailHeader-wrapper_e0846efc > div:nth-child(2) > div > div > div.Description-ctaWrapper_e8d00c38 > div > div > div > div.css-wgi9q7 > div > button:nth-child(1)").wrap(""); // add a tag to be changed
$("#dieselReactWrapper > div > div.css-igz6h5-AppPage__bodyContainer > main > div > div > div.ProductDetails-wrapper_2d124844 > div > div.ProductDetailHeader-wrapper_e0846efc > div:nth-child(2) > div > div > div.Description-ctaWrapper_e8d00c38 > div > div > div > div.css-wgi9q7 > div > a").attr("href", link2); // change link
}
if ("https://www.origin.com" === window.location.origin) { // for origin, in proggress...
var name3 = document.querySelector("#storecontent > section:nth-child(21) > div > origin-store-osp-termsandconditions > div > otkex-legal > div > strong").text();// get game name
alert(name3);
}