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

편집 요약 없음
(문서를 비움)
태그: 비우기 수동 되돌리기
 
(사용자 2명의 중간 판 9개는 보이지 않습니다)
1번째 줄: 1번째 줄:
var doc = document;
var main = function (page) {
var api_params = {
action: 'parse',
page: page,
format: 'json',
prop: ['text', 'categorieshtml'],
disablelimitreport: 1,
disablestylededuplication: 1,
utf8: 1,
formatversion: 'latest',
redirects: 1
};


var api = new mw.Api();
api.get(api_params).done(data => {
console.log('done');
var content = data.parse.text.replaceAll('\n', '').replaceAll('\\', "").replaceAll('href="', 'data-href="'); //이스케이프 문자, 링크 제거
var title = data.parse.title;
var meta = doc.getElementsByTagName('meta');
for (var item of meta) { item.remove() }
doc.querySelector('.header-ads, .bottom-ads').remove()
doc.getElementById('mw-content-text').innerHTML = '<h1>'+title+'</h1>'+content; //내용 갈아치우기
doc.getElementsByClassName('mw-parser-output')[0].id = "mw-content-text"; // 오류 무시
// doc.querySelector('body').innerHTML
var links = doc.querySelectorAll('a:not(.external):not(.new)'); //외부링크 구현 문제, 내부 링크 선택
var linksSize = links.length; //배열 크기 구하기
var docTitle; //var docTitle == var page               
var isinternalLink = true;
// var toLink = function() {};
var toLink = function (link) {
var href = link.target.dataset.href;
if (href.includes('index.php') === true) {
console.log(href);
window.open(href);
} else {
console.log(docTitle);
docTitle = decodeURI(href.split("/").pop());
main(docTitle); //본 함수 반복
isinternalLink = false;
}
}; //내부 링크
//var getLink = function(link) {
//  docTitle = decodeURI(link.target.dataset.href.split("/").pop());
//}; //편집 버튼, 문단 링크
var start = new Date().getTime();
for (var i = 0; i < linksSize; i++) {
links[i].onclick = toLink;
//l_link.onmouseover = getTitle;
}
var end = new Date().getTime();
console.log("time : " + (end - start));
mw.loader.load('/index.php?title=User:cerulean/light.css&action=raw&ctype=text/css', 'text/css');
});
};
var lightWikiOn = document.createElement('span');
lightWikiOn.className = "dropdown-item";
lightWikiOn.innerText = "라이트 모드";
lightWikiOn.onclick = function () {
main(decodeURI(window.location.href.split("/wiki/").pop()));
};
doc.querySelector('.dropdown-item[title="사용자 환경 설정"]').before(lightWikiOn);

2024년 2월 6일 (화) 22:18 기준 최신판