gazellegames ggn: create request with steamid

create request with steamid | Greasemonkey 4.1: ✕ Tampermonkey 4.4: ✔

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name		gazellegames ggn: create request with steamid
// @namespace	 https://gazellegames.net/
// @version		 1.4
// @description	  create request with steamid | Greasemonkey 4.1: ✕  Tampermonkey 4.4: ✔ 
// @author		 hoannsi
// @match		 https://gazellegames.net/requests.php?action=new*
// @require      https://code.jquery.com/jquery-3.1.1.min.js
// @grant		 GM_xmlhttpRequest
// ==/UserScript==

var steamBox = document.getElementById('artist_tr');
steamBox.innerHTML = steamBox.innerHTML + '<br> Steamid: <input id="steamId" size="45" value="" type="text">'

var platformm = document.getElementById('platform')
platformm.selectedIndex = 6;

function html2bb(str) {
    if(typeof str === "undefined") return "";

    str = str.replace(/\r/g, "");    
    str = str.replace(/\n/g, "");    
    str = str.replace(/< *br *\/*>/g, "\n");
    str = str.replace(/< *u *>/g, "[u]");
    str = str.replace(/< *h1*>/g, "[align=center][u]");
    str = str.replace(/< *\/h1*>/g, "[/u]\n\n[/align]");
    str = str.replace(/< *\/p*>/g, "");
    str = str.replace(/< *p*>/g, "");
    str = str.replace(/< *\/ *u *>/g, "[/u]");
    str = str.replace(/< *\/ *li *>/g, "");
    str = str.replace(/< *li *>/g, "[*]");
    str = str.replace(/< *\/ *ul *>/g, "");
    str = str.replace(/< *ul *class=\\*\"bb_ul\\*\" *>/g, "");
    str = str.replace(/< *h2 *class=\"bb_tag\" *>/g, "\n\n[u]");
    str = str.replace(/< *\/ *h2 *>/g, "[/u]");
    str = str.replace(/< *strong *>/g, "[b]");
    str = str.replace(/< *\/ *strong *>/g, "[/b]");
    str = str.replace(/< *i *>/g, "[i]");
    str = str.replace(/< *\/ *i *>/g, "[/i]");
    str = str.replace(/\&quot;/g, "\"");
    str = str.replace(/< *img *src="([^"]*)" *>/g, "");
    str = str.replace(/< *b *>/g, "[b]");
    str = str.replace(/< *\/ *b *>/g, "[/b]");
    str = str.replace(/< *a [^>]*>/g, "");
    str = str.replace(/< *\/ *a *>/g, "");
    //Yeah, all these damn stars. Because people put spaces where they shouldn't.
    return str;
}



(function() {
    'use strict';

    document.getElementById("steamId").addEventListener("blur", function() {			//After the "appid" input loses focus
        GM_xmlhttpRequest({method: "GET",								//We call the Steam API to get info on the game
                           url: "http://store.steampowered.com/api/appdetails?l=en&appids=" + document.getElementById("steamId").value,
                           responseType: "json",
                           onload: function(response) {

                               var gameInfo = response.response[document.getElementById("steamId").value].data;		//We store the data in gameInfo, since it's much easier to access this way
                               document.getElementsByName("title")[0].value = gameInfo.name;								//Get the name of the game

                               document.getElementsByName("description")[0].value = "http://store.steampowered.com/app/"+document.getElementById("steamId").value+"/\n\n[align=center][b][u]About the game[/u][/b][/align]\n" + html2bb(gameInfo.about_the_game); //Get the description, formatted appropriately
                               document.getElementsByName("year")[0].value = gameInfo.release_date.date.split(", ").pop(); //Get the year, which is actually the last number of "release_date.date"

                               //Genres are in an object array. Need to make them lowercase, replace spaces with dots and separate them with ", "
                               var genres = [];
                               gameInfo.genres.forEach(function (genre) {
                                   var tag = genre.description.toLowerCase().replace(/ /g, "."); //Each genre is formatted as mentioned above and added to the "genres" array
                                   switch (tag) {
                                       case "rpg":
                                           tag = "role.playing.game";
                                       default:
                                           genres.push(tag);
                                       case "early.access":
                                           break;
                                   }

                               });
                               document.getElementById("tags").value = genres.join(", ");							//Every string in the "genres" array is then concatenated with ", " between them

                               var request2 = new XMLHttpRequest();
                               request2.open( "GET", "https://gazellegames.net/imgup.php?img=" + gameInfo.header_image.split("?")[0], false ); // false for synchronous request
                               request2.send( null );
                               document.getElementsByName("image")[0].value = request2.responseText;
                           }
                          });
    });

})();