편집 요약 없음 |
(custom-navbar-data 사용) |
||
1번째 줄: | 1번째 줄: | ||
// 원본 : 사용자:하늘/custom-navbar.js | // 원본 : 사용자:하늘/custom-navbar.js | ||
// 수정 : 사용자:Utolee90 | // 수정 : 사용자:Utolee90 | ||
// custom-navbar-data 불러오기 | // custom-navbar-data 불러오기 -> navBarData 형식으로 값이 호출됨. | ||
var | var dataPageName = mw.config.get().wgPageName.replace('.js', '-data.js'); // custom-navbar-data 파일 불러오기 | ||
mw.loader.load('/index.php?title= | mw.loader.load('/index.php?title=' + dataPageName + '&action=raw&ctype=text/javascript'); | ||
// csv 파일 RAW 데이터를 얻기 위해서 필요 | // csv 파일 RAW 데이터를 얻기 위해서 필요 | ||
20번째 줄: | 19번째 줄: | ||
var libreNavLogin = {}; | var libreNavLogin = {}; | ||
libreNavLogin.createItem = function(title, url) { | libreNavLogin.createItem = function(icon, title, url, desc) { | ||
var a = document.createElement('a'); | var a = document.createElement('a'); // 링크 추가 | ||
var iconHTML = document.createElement('span'); // icon 추가 | |||
iconHTML.className = "fas "+icon; | |||
iconHTML.style.color = 'grey'; // 색상 변경 | |||
iconHTML.style.fontSize = '1em'; // 사이즈 변경 | |||
a.className = "dropdown-item", | a.className = "dropdown-item", | ||
a.href = url, | a.href = url, | ||
a.innerHTML = title; | a.innerHTML = title, | ||
a.title = desc; | |||
// icon이 빈 값이 아닐 때 아이콘 추가 | |||
if (icon != '' && icon !=undefined) { | |||
a.prepend(iconHTML); | |||
} | |||
return a; | return a; | ||
}; | }; | ||
libreNavLogin.addNavItem = function(icon, name, url) { | libreNavLogin.addNavItem = function(icon, name, url, desc) { | ||
var node = this.createItem(name, url); | var node = this.createItem(name, url, desc); | ||
document.getElementsByClassName('dropdown-divider')[0].before(node); | document.getElementsByClassName('dropdown-divider')[0].before(node); | ||
}; | }; | ||
libreNavLogin.setNavItems = function() { | libreNavLogin.setNavItems = function() { | ||
for (const item of navBarData.newNavItems) { | |||
this.addNavItem(item[0], item[1], item[2], item[3]); | |||
for (const item of | |||
this.addNavItem( | |||
} | } | ||
}; | }; |
2022년 11월 10일 (목) 23:30 판
// 원본 : 사용자:하늘/custom-navbar.js
// 수정 : 사용자:Utolee90
// custom-navbar-data 불러오기 -> navBarData 형식으로 값이 호출됨.
var dataPageName = mw.config.get().wgPageName.replace('.js', '-data.js'); // custom-navbar-data 파일 불러오기
mw.loader.load('/index.php?title=' + dataPageName + '&action=raw&ctype=text/javascript');
// csv 파일 RAW 데이터를 얻기 위해서 필요
function getRaw(title) {
var raw;
$.ajax({
async: false,
url: location.origin + mw.util.getUrl(title || mw.title, { action: 'raw' }),
success: function (data) { raw = data; }
});
return raw;
}
// 아이템 추가
var libreNavLogin = {};
libreNavLogin.createItem = function(icon, title, url, desc) {
var a = document.createElement('a'); // 링크 추가
var iconHTML = document.createElement('span'); // icon 추가
iconHTML.className = "fas "+icon;
iconHTML.style.color = 'grey'; // 색상 변경
iconHTML.style.fontSize = '1em'; // 사이즈 변경
a.className = "dropdown-item",
a.href = url,
a.innerHTML = title,
a.title = desc;
// icon이 빈 값이 아닐 때 아이콘 추가
if (icon != '' && icon !=undefined) {
a.prepend(iconHTML);
}
return a;
};
libreNavLogin.addNavItem = function(icon, name, url, desc) {
var node = this.createItem(name, url, desc);
document.getElementsByClassName('dropdown-divider')[0].before(node);
};
libreNavLogin.setNavItems = function() {
for (const item of navBarData.newNavItems) {
this.addNavItem(item[0], item[1], item[2], item[3]);
}
};
libreNavLogin.removeItem = function(name) {
var Selector = '[title="' + name + '"]';
document.querySelector(Selector).remove();
};
libreNavLogin.setNavItems();
var api_params = {
action: 'query',
list: 'categorymembers',
cmtitle: '분류:한자/문자',
cmlimit: 'max',
format: 'json',
cmtype: 'page'
};
function navItem() {
this.root = document.createElement('li');
this.root.id = 'hanja-random';
this.root.className = "nav-item";
document.querySelector('.nav.navbar-nav').append(this.root);
function link() {
var span = () => { return document.createElement('span'); };
var a = document.createElement('a');
this.root = a;
this.root.className = "nav-link";
this.root.title = "한자 랜덤문서";
this.icon = span();
this.icon.style.fontWeight = "600",
this.icon.innerText = '漢';
this.title = span();
this.title.className = "hide-title",
this.title.innerText = ' 한자 랜덤';
this.root.append(this.icon);
this.root.append(this.title);
var isloaded = false;
this.root.onmouseenter = function() {
if (isloaded === false) {
var link = document.querySelector('#hanja-random a');
new mw.Api().get(api_params).done(function(data) {
var pages = data.query.categorymembers;
var randomTitle = pages[Math.floor(Math.random() * pages.length)].title;
link.href = "/wiki/" + randomTitle;
isloaded = true;
console.log(randomTitle);
});
}
};
}
this.link = new link();
this.root.append(this.link.root);
}
// document.querySelector('.hide-logout.logout-btn').remove();
new navItem();