A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

109 行
3.5 KiB

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