문서 편집 권한이 없습니다. 다음 이유를 확인해주세요: 여기에는 다른 사용자의 개인 설정이 포함되어 있기 때문에 이 자바스크립트 문서를 편집할 수 없습니다. 문서의 원본을 보거나 복사할 수 있습니다. // 원본 : 사용자:하늘/custom-navbar.js // 수정 : 사용자:Utolee90 // custom-navbar-data 불러오기 -> navBarData 형식으로 값이 호출됨. var dataPageName = mw.config.get().wgPageName.replace('.js', '-data.json'); // custom-navbar-data 파일이름 // 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; } console.log(getRaw(dataPageName)); // 아이템 추가 var libreNavLogin = {}; libreNavLogin.navBarData = JSON.parse(getRaw(dataPageName)); libreNavLogin.titleMap = { "dropRC": "위키의 최근 바뀐 목록 [alt-shift-r]", "dropRandom": "무작위로 선택된 문서 불러오기 [alt-shift-x]", "dropMap": "https://maps.librewiki.net/", "dropBoard": "게시판", "dropWikiBoard": "https://bbs.librewiki.net/" "dropFreeBoard": "https://bbs.librewiki.net/freeboard", "dropTools": "도구", "dropSpecial": "특수:특수문서", "dropUpload": "특수:올리기", "dropHelp": "도움말", "dropSummary": "리브레_위키:도움말", "dropSyntax": "도움말:위키_문법", "dropTex": "도움말:TeX_문법" }; libreNavLogin.createItem = function(icon, title, url, desc) { var a = document.createElement('a'); // 링크 추가 var iconHTML = document.createElement('i'); // icon 추가 iconHTML.className = "fa "+icon; iconHTML.style.color = '#373a3c'; // 색상 변경 iconHTML.style.fontSize = '0.9em'; // 사이즈 변경 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(icon, name, url, desc); document.getElementsByClassName('dropdown-divider')[0].before(node); }; libreNavLogin.addMenuItem = function(icon, name, url, desc, part) { }; libreNavLogin.removeItem = function(name) { var Selector = '[title="' + name + '"]'; // 시작하는 데이터로 수정 document.querySelector(Selector).remove(); }; libreNavLogin.setNavItems = function() { for (const item of this.navBarData.newNavItems) { this.addNavItem(item[0], item[1], item[2], item[3]); } for (const key in this.titleMap) { // titleMap에서 key값 추출 if (this.navBarData[key] ) { this.removeItem(this.titleMap[key]); } } // 로그아웃 버튼 지우기 여부 if(this.navBarData.dropLogout) { document.querySelector('.hide-logout.logout-btn').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); } // new navItem(); 사용자:Utolee90/custom-navbar.js 문서로 돌아갑니다.