🏠 Home 

Transfermarkt Nation Filter

Filter Transfermarkt


Installer dette script?
  1. /* This program is free software. It comes without any warranty, to
  2. * the extent permitted by applicable law. You can redistribute it
  3. * and/or modify it under the terms of the Do What The #### You Want
  4. * To Public License, Version 2, as published by Sam Hocevar. See
  5. * http://www.wtfpl.net/ for more details. */
  6. // ==UserScript==
  7. // @name Transfermarkt Nation Filter
  8. // @namespace fussball
  9. // @include https://fussballcup.de/
  10. // @version 0.1.2
  11. // @description Filter Transfermarkt
  12. // @author Philipp, edited by mot33 / 2018
  13. // @connect <value>
  14. // ==/UserScript==
  15. var injectObj = 'show_german_switch';
  16. /**
  17. * e. g. Gracemonkey won't let us access custom script from webpage (e. g. as <a href=javascript:...)
  18. * use this scirpt to inject JS-Code directely in DOM-tree so you can access this code from web page
  19. */
  20. function injectJS(code, id){
  21. var scriptId = "custom_script_" + id;
  22. if(document.getElementById(scriptId)){
  23. // element allready added; ignore!
  24. return;
  25. }
  26. var script = document.createElement('script');
  27. script.id = "script_" + id;
  28. script.appendChild(document.createTextNode(code));
  29. (document.body || document.head || document.documentElement).appendChild(script);
  30. }
  31. injectJS(`
  32. current_view_other = true;
  33. current_view_german = true;
  34. var flag_filter = "flag_filer_table_ok";
  35. /**
  36. * really simple log system
  37. */
  38. function logError(msg){
  39. console.log("ERROR ==> " + appName + ": " + msg);
  40. }
  41. function logWarning(msg){
  42. }
  43. function logInfo(msg){
  44. }
  45. var timeout = 5000;
  46. /**
  47. * Simply creates async html request with url theURL; calls back callback with r###lt string as first parameter
  48. *
  49. * Case of error; null is returned as r###lt String
  50. */
  51. function httpGetAsync(theUrl, callback){
  52. logInfo('send Http request: ' + theUrl);
  53. var xmlHttp = new XMLHttpRequest();
  54. xmlHttp.onreadystatechange = function() {
  55. if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
  56. logInfo('http request returned: ' + xmlHttp.responseText);
  57. callback(xmlHttp.responseText);
  58. }
  59. }
  60. xmlHttp.open('GET', theUrl, true); // true for asynchronous
  61. xmlHttp.send(null);
  62. // handle timeout
  63. window.setTimeout(function(){
  64. if (xmlHttp.readyState != 4 || xmlHttp.status != 200){
  65. // something went wrong
  66. // cancel
  67. xmlHttp.abort();
  68. // call callback with error
  69. callback(null);
  70. }
  71. }, timeout);
  72. }
  73. /**
  74. * @constructor
  75. * @param {Array[String]} params - Array containing all parameter (
  76. * @param {string} callback - to be called with r###lt String as first parameter
  77. */
  78. function httpRequestFootball(params, callback){
  79. var paramString = '';
  80. var preAnd = '';
  81. for (var i=0; i<params.length; i++){
  82. var para = params[i];
  83. paramString += preAnd + (para[0] + '=' + para[1]);
  84. preAnd = '&';
  85. }
  86. httpGetAsync('/index.php?w=' + worldId + '&' + paramString, callback);
  87. }
  88. function getMaxPlayerMarketPages(){
  89. var searchR###lts = document.getElementsByClassName('table-container')[0];
  90. if(searchR###lts.children.length == 2){
  91. // only one page available
  92. return 1;
  93. }else{
  94. // more than one page available
  95. var avail_pages = searchR###lts.children[1].children;
  96. avail_pages = avail_pages[avail_pages.length - 1].innerHTML;
  97. return parseInt(avail_pages);
  98. }
  99. }
  100. function getCurrentPlayerMarketPage(){
  101. var searchR###lts = document.getElementsByClassName('table-container')[0];
  102. if(searchR###lts.children.length == 2){
  103. // only one page available
  104. return 1;
  105. }else{
  106. // more than one page available
  107. return parseInt(searchR###lts.getElementsByTagName('strong')[0].innerHTML);
  108. }
  109. }
  110. function pageToPlayers(page){
  111. var searchR###lts = page.getElementsByClassName('table-container')[0];
  112. odds = searchR###lts.getElementsByClassName('odd');
  113. evens = searchR###lts.getElementsByClassName('even');
  114. ret = new Array(odds.length + evens.length);
  115. for(var i=0; i<odds.length; i++){
  116. ret[2*i] = odds[i];
  117. ret[2*i+1] = evens[i];
  118. }
  119. if(odds.length > evens.length){
  120. ret[odds.length + evens.length -1] = odds[odds.length - 1];
  121. }
  122. return ret;
  123. }
  124. /**
  125. * synchron (blocking) function
  126. * not cached; downloads content
  127. * will search all players
  128. * call callback with first parameter: list of all found players
  129. */
  130. function findPlayersOnMarket(callback, page){
  131. httpRequestFootball([['area', 'user'],
  132. ['module', 'transfermarket'],
  133. ['action', 'index'],
  134. ['path', 'index.php'],
  135. ['layout', 'none'],
  136. ['club', ''],
  137. ['_qf__searchform', ''],
  138. ['pos', page*25-25],
  139. ],
  140. function(r###ltString){
  141. var parser = document.createElement('html');
  142. parser.innerHTML = JSON.parse(r###ltString).content;
  143. callback(pageToPlayers(parser));
  144. });
  145. }
  146. function showAll(){
  147. set_visible(true, true);
  148. }
  149. function showNoGerman(){
  150. set_visible(false, true);
  151. }
  152. function set_visible(german, other){
  153. current_view_german = german;
  154. current_view_other = other;
  155. // set flag: if table modified, this element should (!) be deleted!
  156. var div = document.createElement('div');
  157. div.id = flag_filter;
  158. document.getElementsByClassName('container transfermarket')[0].appendChild(div);
  159. // generate visibility flags
  160. german = german ? '' : 'none';
  161. other = other ? '' : 'none';
  162. // show / hide + color adjust
  163. is_odd = true;
  164. var players = pageToPlayers(document);
  165. for(var x=0; x<players.length; x++){
  166. try{
  167. // show/hide
  168. var player = players[x];
  169. if(player.children[0].children[0].src.endsWith('DEU.gif')){
  170. // german player
  171. player.style.display = german;
  172. }else{
  173. // other
  174. player.style.diplay = other;
  175. }
  176. // color adjust
  177. if(player.style.display == ''){
  178. if(is_odd){
  179. player.className = "odd";
  180. }else{
  181. player.className = "even";
  182. }
  183. is_odd = !is_odd;
  184. }
  185. }catch(err){
  186. console.log(err);
  187. }
  188. }
  189. }
  190. // automatic adjust
  191. function fix_changes(){
  192. if(document.getElementById(flag_filter) == null){
  193. // need to update!
  194. set_visible(current_view_german, current_view_other);
  195. }
  196. }
  197. window.setInterval(function() { fix_changes() }, 1000);
  198. `, 'transfermarket_filter');
  199. function transfermarkt_filter (){
  200. // check for need to do anything
  201. current_url = window.location.href;
  202. if (current_url.indexOf('module=transfermarket') == -1){
  203. return;
  204. }
  205. if (current_url.indexOf('action=index') == -1){
  206. return;
  207. }
  208. // yes, it's transferemarkt page
  209. if(document.getElementById(injectObj) != null){
  210. // allready added
  211. return;
  212. }
  213. var s = '&#10148; <a href=javascript:showAll()>Alle Spieler</a><br />&#10148; <a href=javascript:showNoGerman()>Nur Ausländische Spieler<br /> </a> &#10148; <a target= _blank href=http://forum.fussballcup.de/forumdisplay.php?f=20()>Spieler Angebote aus dem Forum</a>';
  214. var div = document.createElement('div');
  215. div.id = injectObj;
  216. div.innerHTML = s;
  217. document.getElementsByClassName('table-container')[0].children[0].appendChild(div);
  218. }
  219. window.setInterval(function() { transfermarkt_filter ();}, 2500);