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.
 
 
 
 
 

101 lines
3.1 KiB

  1. function potd_set_background() {
  2. var d = new Date();
  3. var callback = "like_a_boss";
  4. var date = (d.getUTCFullYear()) + "-" + zero_pad(d.getUTCMonth() + 1, 2) + "-" + zero_pad(d.getUTCDate(), 2);
  5. var base = "http://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 = "like_a_faust";
  24. var base = "http://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. url = url.replace(/\/commons\//, "/commons/thumb/");
  49. var s = get_window_size();
  50. var winwidth = s[0];
  51. var winheight = s[1];
  52. var width = winwidth;
  53. if (imgwidth/imgheight > winwidth/winheight) {
  54. width = Math.round((imgwidth/imgheight) * winheight);
  55. }
  56. url += "/" + width + "px-" + filename;
  57. document.body.style.backgroundImage="url('" + url + "')";
  58. document.getElementById("bg_image_link").href = descurl;
  59. }
  60. function zero_pad(value, length) {
  61. value = String(value);
  62. length = length || 2;
  63. while (value.length < length) {
  64. value = "0" + value;
  65. }
  66. return value;
  67. }
  68. function get_window_size() {
  69. // See http://www.javascripter.net/faq/browserw.htm
  70. var width = 1024,
  71. height = 768;
  72. if (document.body && document.body.offsetWidth && document.body.offsetHeight) {
  73. width = document.body.offsetWidth;
  74. height = document.body.offsetHeight;
  75. }
  76. if (document.compatMode=="CSS1Compat" && document.documentElement && document.documentElement.offsetWidth && document.documentElement.offsetHeight) {
  77. width = document.documentElement.offsetWidth;
  78. height = document.documentElement.offsetHeight;
  79. }
  80. if (window.innerWidth && window.innerHeight) {
  81. width = window.innerWidth;
  82. height = window.innerHeight;
  83. }
  84. return [width, height];
  85. }