A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

130 строки
4.2 KiB

  1. function potd_set_background() {
  2. var cookie = get_cookie("EarwigBackgroundCache");
  3. if (cookie) {
  4. try {
  5. data = JSON.parse(cookie);
  6. var url = data.url;
  7. var descurl = data.descurl;
  8. var imgwidth = data.imgwidth;
  9. var imgheight = data.imgheight;
  10. if (url && descurl && imgwidth && imgheight) {
  11. set_background(url, descurl, imgwidth, imgheight);
  12. return;
  13. }
  14. }
  15. catch (SyntaxError) {}
  16. }
  17. var d = new Date();
  18. var callback = "earwigpotd1";
  19. var date = (d.getUTCFullYear()) + "-" + zero_pad(d.getUTCMonth() + 1, 2) + "-" + zero_pad(d.getUTCDate(), 2);
  20. var base = "//commons.wikimedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Template:Potd/";
  21. var url = base + date + "&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_file_name(data);
  27. };
  28. script.src = url;
  29. head.appendChild(script);
  30. }
  31. function parse_file_name(data) {
  32. var content = "";
  33. var res = data["query"]["pages"];
  34. for (pageid in res) {
  35. content = res[pageid]["revisions"][0]["*"];
  36. }
  37. var filename = /\{\{Potd filename\|(1=)?(.*?)\|.*?\}\}/.exec(content)[2];
  38. var callback = "earwigpotd2";
  39. var base = "//commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=url|size&format=json&titles=File:";
  40. var url = base + escape(filename) + "&callback=" + callback;
  41. var script = document.createElement("script");
  42. var head = document.getElementsByTagName("head")[0];
  43. window[callback] = function(data) {
  44. head.removeChild(script);
  45. parse_file_url(data, escape(filename.replace(/ /g, "_")));
  46. };
  47. script.src = url;
  48. head.appendChild(script);
  49. }
  50. function parse_file_url(data, filename) {
  51. var url = "";
  52. var descurl = "";
  53. var imgwidth = 1024;
  54. var imgheight = 768;
  55. var res = data["query"]["pages"];
  56. for (pageid in res) {
  57. r = res[pageid]["imageinfo"][0];
  58. url = r["url"];
  59. descurl = r["descriptionurl"];
  60. imgwidth = r["width"];
  61. imgheight = r["height"];
  62. }
  63. set_background(url, descurl, imgwidth, imgheight);
  64. var data = {"url": url, "descurl": descurl, "imgwidth": imgwidth, "imgheight": imgheight};
  65. var now = new Date();
  66. var expires = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + 1);
  67. set_cookie_with_date("EarwigBackgroundCache", JSON.stringify(data), expires);
  68. }
  69. function set_background(url, descurl, imgwidth, imgheight) {
  70. var s = get_window_size();
  71. var winwidth = s[0];
  72. var winheight = s[1];
  73. var width = winwidth;
  74. if (imgwidth/imgheight > winwidth/winheight) {
  75. width = Math.round((imgwidth/imgheight) * winheight);
  76. }
  77. if (width >= imgwidth) {
  78. document.body.style.backgroundImage = "url('" + url + "')";
  79. if (width > imgwidth) {
  80. document.body.style.setProperty("background-size", "cover");
  81. }
  82. } else {
  83. url = url.replace(/\/commons\//, "/commons/thumb/") + "/" + width + "px-" + filename;
  84. document.body.style.backgroundImage = "url('" + url + "')";
  85. }
  86. document.getElementById("bg_image_link").href = descurl;
  87. }
  88. function zero_pad(value, length) {
  89. value = String(value);
  90. length = length || 2;
  91. while (value.length < length) {
  92. value = "0" + value;
  93. }
  94. return value;
  95. }
  96. function get_window_size() {
  97. // See http://www.javascripter.net/faq/browserw.htm
  98. var width = 1024,
  99. height = 768;
  100. if (document.body && document.body.offsetWidth && document.body.offsetHeight) {
  101. width = document.body.offsetWidth;
  102. height = document.body.offsetHeight;
  103. }
  104. if (document.compatMode=="CSS1Compat" && document.documentElement && document.documentElement.offsetWidth && document.documentElement.offsetHeight) {
  105. width = document.documentElement.offsetWidth;
  106. height = document.documentElement.offsetHeight;
  107. }
  108. if (window.innerWidth && window.innerHeight) {
  109. width = window.innerWidth;
  110. height = window.innerHeight;
  111. }
  112. return [width, height];
  113. }