사용자:하늘/mobile.js: 두 판 사이의 차이

편집 요약 없음
잔글 (Chirho님이 사용자:Cerulean/mobile.js 문서를 넘겨주기를 만들지 않고 사용자:하늘/mobile.js 문서로 이동했습니다: "Cerulean" 사용자의 이름을 "하늘"(으)로 바꿀 때 문서를 자동으로 이동했습니다)
(차이 없음)

2022년 5월 11일 (수) 10:30 판

var image_containers = document.getElementsByClassName('using-mobiledata');
var imagenames = [];
var iter = 0;
for (const contain of image_containers) {
  imagenames[iter] = contain.innerText;
  contain.style.cssText = "width: 100px;height: 100px;";
  iter++;
}

// imagenames에 이미지 이름 저장

var params = {
    action: "query",
    format: "json",
    prop: "imageinfo",
    titles: imagenames,
    utf8: 1,
    iiprop: "url",
    formatversion: "latest",
  },
  api = new mw.Api();

api.get(params).done(function(data) {
  var pages = data.query.pages;
  var iter = 0;
  for (const image of pages) {
    for (const contain of image_containers) {
      var colonIndex = contain.innerText.indexOf(':');
      var ns = contain.innerText.slice(0, colonIndex);
      ns = ns.replace('file', '파일').replace('File', '파일');
      var filename = contain.innerText.slice(colonIndex + 1);
      filename = filename.charAt(0).toUpperCase() + filename.slice(1);
      filename = ns + ':' + filename;
	console.log(filename);
      if (image.missing === true && image.known !== true) { //지우면 작동 불가
      } else if (filename === image.title) {
        contain.innerText = contain.innerText + '\n사진을 보려면 클릭하세요.';
        $(contain).click(function() {
          contain.style.cssText = "display:inline;";
          contain.innerHTML = '<img decode="async" src="' + image.imageinfo[0].url + '"></img>';
        });
      }
    }
  }
});