Play Flash games on Kongregate with Flash again!
目前為
// ==UserScript==
// @name Kongregate Flash games fixer
// @version 1.0
// @description Play Flash games on Kongregate with Flash again!
// @author Matrix4348
// @license MIT
// @match *://*.konggames.com/games/*/*/frame/*
// @grant none
// @namespace https://greasyfork.org/users/4818
// ==/UserScript==
// The script must be restrained to the Flash iframes (the URL for the html games iframes look a bit different, but there may be some exceptions).
if ((document.URL.search("/frame/")>-1)&(document.body.innerHTML.search("kong_flash_variables")>-1)){
// First, we need to extract the link to the swf (the game file).
var file_url0, file_url, file_url_base;
var scripts=document.getElementsByTagName("script");
for(var i=0; i<scripts.length;i++) {var script_text=scripts[i].text;
var url_text;
if(script_text.indexOf("game_swf")!== -1) {
url_text=String(script_text.match(/game_swf\"\:\"(.*?)\"\,\"game_url/g));
file_url0="https://"+decodeURIComponent(url_text.substring(17,(url_text.length/2)-11));
break;
}
else if(script_text.indexOf("swfurl")!== -1) {
url_text=String(script_text.match(/swfurl\"\:\"(.*?)\"\,\"flashvars/g));
file_url0=decodeURI(url_text.substring(9,url_text.length-12));
break;
};
};
file_url=file_url0.substring(file_url0.search("//"),file_url0.length-1);
file_url_base="http:"+file_url.substring(0,file_url.search("/live/")+6);
// Now, let's write in the page's HTML.
var a=document.createElement("script");
a.id="Fixing area";
// IMPORTANT: Apparently, something in the code knows the correct flashvars, this is why I will not input any.
a.innerHTML=
`//<![CDATA[
gameLoader = {
loadGame: function(urlOptions) {
var swf_location = "`+file_url+`";
var swfobject_flash_vars = {};
if(typeof(kong_flash_variables) == "object"){
for(var k in kong_flash_variables){
swfobject_flash_vars[k] = encodeURIComponent(kong_flash_variables[k]);
}
}
swfobject.embedSWF(swf_location, "gamediv","100%","100%","6","/flash/expressInstall.swf",swfobject_flash_vars,{"bgcolor":"#000000","allownetworking":"all","allowscriptaccess":"always","base":"`+file_url_base+`"},{});
}
}
function activateGameWithFlash(urlOptions) {
if (!urlOptions) {
urlOptions = '';
}
gameLoader.loadGame(urlOptions);
document.fire('game:activated');
};
activateGameWithFlash();
//]]>`;
document.body.appendChild(a);
}