A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

182 rivejä
5.9 KiB

  1. function set_background_potd() {
  2. if (cache_cookie()) return;
  3. var d = new Date();
  4. var callback = "earwigpotd1";
  5. var date = (d.getUTCFullYear()) + "-" + zero_pad(d.getUTCMonth() + 1, 2) + "-" + zero_pad(d.getUTCDate(), 2);
  6. var base = "//commons.wikimedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Template:Potd/";
  7. var url = base + date + "&callback=" + callback;
  8. var script = document.createElement("script");
  9. var head = document.getElementsByTagName("head")[0];
  10. window[callback] = function(data) {
  11. head.removeChild(script);
  12. parse_potd_file_name(data);
  13. };
  14. script.src = url;
  15. head.appendChild(script);
  16. }
  17. function set_background_list() {
  18. if (cache_cookie()) return;
  19. var callback = "earwigpotd1";
  20. var base = "//commons.wikimedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=User:The+Earwig/POTD";
  21. var url = base + "&callback=" + callback;
  22. var script = document.createElement("script");
  23. var head = document.getElementsByTagName("head")[0];
  24. window[callback] = function(data) {
  25. head.removeChild(script);
  26. parse_list_file_name(data);
  27. };
  28. script.src = url;
  29. head.appendChild(script);
  30. }
  31. function cache_cookie() {
  32. var cookie = get_cookie("EarwigBackgroundCache");
  33. if (cookie) {
  34. try {
  35. data = JSON.parse(cookie);
  36. var filename = data.filename;
  37. var url = data.url;
  38. var descurl = data.descurl;
  39. var imgwidth = data.imgwidth;
  40. var imgheight = data.imgheight;
  41. if (filename && url && descurl && imgwidth && imgheight) {
  42. set_background(filename, url, descurl, imgwidth, imgheight);
  43. return true;
  44. }
  45. }
  46. catch (SyntaxError) {}
  47. }
  48. return false;
  49. }
  50. function parse_potd_file_name(data) {
  51. var content = "";
  52. var res = data["query"]["pages"];
  53. for (pageid in res) {
  54. content = res[pageid]["revisions"][0]["*"];
  55. }
  56. var filename = /\{\{Potd filename\|(1=)?(.*?)\|.*?\}\}/.exec(content)[2];
  57. var callback = "earwigpotd2";
  58. var base = "//commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=url|size&format=json&titles=File:";
  59. var url = base + escape(filename) + "&callback=" + callback;
  60. var script = document.createElement("script");
  61. var head = document.getElementsByTagName("head")[0];
  62. window[callback] = function(data) {
  63. head.removeChild(script);
  64. parse_file_url(data, escape(filename.replace(/ /g, "_")));
  65. };
  66. script.src = url;
  67. head.appendChild(script);
  68. }
  69. function parse_list_file_name(data) {
  70. var content = "";
  71. var res = data["query"]["pages"];
  72. for (pageid in res) {
  73. content = res[pageid]["revisions"][0]["*"];
  74. }
  75. var filenames = [];
  76. var regexp = /\*\*?\s*\[\[:File:(.*?)\]\]/g;
  77. while ((match = regexp.exec(content)) !== null) {
  78. filenames.push(match[1]);
  79. }
  80. var filename = filenames[Math.floor(Math.random() * filenames.length)];
  81. var callback = "earwigpotd2";
  82. var base = "//commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=url|size&format=json&titles=File:";
  83. var url = base + escape(filename) + "&callback=" + callback;
  84. var script = document.createElement("script");
  85. var head = document.getElementsByTagName("head")[0];
  86. window[callback] = function(data) {
  87. head.removeChild(script);
  88. parse_file_url(data, escape(filename.replace(/ /g, "_")));
  89. };
  90. script.src = url;
  91. head.appendChild(script);
  92. }
  93. function parse_file_url(data, filename) {
  94. var url = "";
  95. var descurl = "";
  96. var imgwidth = 1024;
  97. var imgheight = 768;
  98. var res = data["query"]["pages"];
  99. for (pageid in res) {
  100. r = res[pageid]["imageinfo"][0];
  101. url = r["url"];
  102. descurl = r["descriptionurl"];
  103. imgwidth = r["width"];
  104. imgheight = r["height"];
  105. }
  106. set_background(filename, url, descurl, imgwidth, imgheight);
  107. var data = {"filename": filename, "url": url, "descurl": descurl, "imgwidth": imgwidth, "imgheight": imgheight};
  108. var expires = new Date();
  109. expires.setUTCMilliseconds(0);
  110. expires.setUTCSeconds(0);
  111. expires.setUTCMinutes(0);
  112. expires.setUTCHours(0);
  113. expires.setUTCDate(expires.getUTCDate() + 1);
  114. set_cookie_with_date("EarwigBackgroundCache", JSON.stringify(data), expires);
  115. }
  116. function set_background(filename, url, descurl, imgwidth, imgheight) {
  117. var s = get_window_size();
  118. var winwidth = s[0];
  119. var winheight = s[1];
  120. var width = winwidth;
  121. if (imgwidth/imgheight > winwidth/winheight) {
  122. width = Math.round((imgwidth/imgheight) * winheight);
  123. }
  124. if (width >= imgwidth) {
  125. document.body.style.backgroundImage = "url('" + url + "')";
  126. if (width > imgwidth) {
  127. document.body.style.setProperty("background-size", "cover");
  128. }
  129. } else {
  130. url = url.replace(/\/commons\//, "/commons/thumb/") + "/" + width + "px-" + filename;
  131. document.body.style.backgroundImage = "url('" + url + "')";
  132. }
  133. document.getElementById("bg_image_link").href = descurl;
  134. }
  135. function zero_pad(value, length) {
  136. value = String(value);
  137. length = length || 2;
  138. while (value.length < length) {
  139. value = "0" + value;
  140. }
  141. return value;
  142. }
  143. function get_window_size() {
  144. // See http://www.javascripter.net/faq/browserw.htm
  145. if (document.body && document.body.offsetWidth && document.body.offsetHeight) {
  146. return [document.body.offsetWidth, document.body.offsetHeight];
  147. }
  148. if (document.compatMode=="CSS1Compat" && document.documentElement && document.documentElement.offsetWidth && document.documentElement.offsetHeight) {
  149. return [document.documentElement.offsetWidth, document.documentElement.offsetHeight];
  150. }
  151. if (window.innerWidth && window.innerHeight) {
  152. return [window.innerWidth, window.innerHeight];
  153. }
  154. return [1024, 768];
  155. }