A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

134 lines
4.3 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 expires = new Date();
  66. expires.setUTCMilliseconds(0);
  67. expires.setUTCSeconds(0);
  68. expires.setUTCMinutes(0);
  69. expires.setUTCHours(0);
  70. expires.setUTCDate(expires.getUTCDate() + 1);
  71. set_cookie_with_date("EarwigBackgroundCache", JSON.stringify(data), expires);
  72. }
  73. function set_background(url, descurl, imgwidth, imgheight) {
  74. var s = get_window_size();
  75. var winwidth = s[0];
  76. var winheight = s[1];
  77. var width = winwidth;
  78. if (imgwidth/imgheight > winwidth/winheight) {
  79. width = Math.round((imgwidth/imgheight) * winheight);
  80. }
  81. if (width >= imgwidth) {
  82. document.body.style.backgroundImage = "url('" + url + "')";
  83. if (width > imgwidth) {
  84. document.body.style.setProperty("background-size", "cover");
  85. }
  86. } else {
  87. url = url.replace(/\/commons\//, "/commons/thumb/") + "/" + width + "px-" + filename;
  88. document.body.style.backgroundImage = "url('" + url + "')";
  89. }
  90. document.getElementById("bg_image_link").href = descurl;
  91. }
  92. function zero_pad(value, length) {
  93. value = String(value);
  94. length = length || 2;
  95. while (value.length < length) {
  96. value = "0" + value;
  97. }
  98. return value;
  99. }
  100. function get_window_size() {
  101. // See http://www.javascripter.net/faq/browserw.htm
  102. var width = 1024,
  103. height = 768;
  104. if (document.body && document.body.offsetWidth && document.body.offsetHeight) {
  105. width = document.body.offsetWidth;
  106. height = document.body.offsetHeight;
  107. }
  108. if (document.compatMode=="CSS1Compat" && document.documentElement && document.documentElement.offsetWidth && document.documentElement.offsetHeight) {
  109. width = document.documentElement.offsetWidth;
  110. height = document.documentElement.offsetHeight;
  111. }
  112. if (window.innerWidth && window.innerHeight) {
  113. width = window.innerWidth;
  114. height = window.innerHeight;
  115. }
  116. return [width, height];
  117. }