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

편집 요약 없음
편집 요약 없음
 
(사용자 2명의 중간 판 14개는 보이지 않습니다)
4번째 줄: 4번째 줄:
  */
  */
if (mw.config.exists("wgIsArticle") && mw.config.exists("wgPageName") && mw.config.exists("wgArticlePath")) {
if (mw.config.exists("wgIsArticle") && mw.config.exists("wgPageName") && mw.config.exists("wgArticlePath")) {
    var conf = mw.config.get(["wgIsArticle", "wgPageName", "wgArticlePath"]);
  var conf = mw.config.get(["wgIsArticle", "wgPageName", "wgArticlePath"]);
    if (conf.wgIsArticle) {
 
        var itemName = "pageBreadcumbs";
  mw.loader.load('oojs-ui');
  mw.loader.load('mediawiki.notification');
        function initStorageIfRequired() {
 
            if (localStorage.getItem(itemName) == null)
  if (conf.wgIsArticle) {
                localStorage.setItem(itemName, "[]");
    var itemName = "pageBreadcumbs";
        }
 
    function initStorageIfRequired() {
        function setStorage(value) {
      if (localStorage.getItem(itemName) == null)
            initStorageIfRequired();
        localStorage.setItem(itemName, "[]");
            localStorage.setItem(itemName, JSON.stringify(value.slice(-20)));
    }
        }
 
    function setStorage(value) {
        function getStorage() {
      initStorageIfRequired();
            initStorageIfRequired();
      localStorage.setItem(itemName, JSON.stringify(value.slice(-20)));
            return JSON.parse(localStorage.getItem(itemName));
    }
 
    function getStorage() {
      initStorageIfRequired();
      return JSON.parse(localStorage.getItem(itemName));
    }
 
    function makeBreadBar(arr, active) {
      var ol = document.createElement("ol");
      ol.style.display = 'inline-block';
      ol.style.margin = '0.5em',
      ol.className = "breadcrumb";
      $(ol).append('<li id="cleanBreads" style=""><a href="javascript:(function(){})();" style="color: red;"><span class="fa fa-trash"></span></a></li>');
      ol.querySelector('li#cleanBreads > a').addEventListener("click", function() {
        OO.ui.confirm("진짜로 빵가루를 전부 다 청소할까요?").done(confirmed => {
          if (confirmed) {
            localStorage.setItem(itemName, "[]");
            mw.notification.autoHideSeconds = {'short': 1.5};
            mw.notify('강제 새로고침하면 지워져 있을겁니다. :)');
          }
        });
      });
 
      // 최근 10개만 역순으로 제작. 중복이 있으면 제외
      var limitCnt = 10;
      var newArr = [];
      var j = 0;
      while (newArr.length < Math.min(limitCnt, arr.length) && j <= arr.length - 1) {
        if (newArr.indexOf(arr[arr.length - 1 - j]) == -1) {
          newArr.push(arr[arr.length - 1 - j]);
         }
         }
         j++;
         function makeBreadBar(arr, active) {
      }
            var ol = document.createElement("ol");
      for (var i = 0; i < newArr.length; i++) {
            ol.className = "breadcrumb";
        var now = newArr[i];
            ol.style.height = "max-content", // 높이 결정, 파이어폭스도
        var li = document.createElement("li");
            ol.style.margin = '0.5em',
        if (now == active) {
            ol.style.display = 'flex',
          li.className = "active";
            ol.style.flexWrap = 'wrap';
          li.textContent = now;
   
        } else {
            // 최근 10개만 역순으로 제작. 중복이 있으면 제외
          var anchor = document.createElement("a");
            var limitCnt = 10;
          anchor.href = conf.wgArticlePath.replace('$1', now);
            var newArr = [];
          anchor.title = now;
            var j = 0;
          anchor.textContent = now;
            while (newArr.length < Math.min(limitCnt, arr.length) && j<=arr.length-1) {
          li.appendChild(anchor);
                if (newArr.indexOf(arr[arr.length-1-j]) ==-1) {
                    newArr.push(arr[arr.length-1-j]); 
                }
                j++;
            }
            for (var i = 0; i < newArr.length; i++) {
                var now = newArr[i];
                var li = document.createElement("li");
                if (now == active) {
                    li.className = "active";
                    li.textContent = now;
                } else {
                    var anchor = document.createElement("a");
                    anchor.href = conf.wgArticlePath.replace('$1', now);
                    anchor.title = now;
                    anchor.textContent = now;
                    li.appendChild(anchor);
                }
                ol.appendChild(li);
            }
            $(ol).append = '<li id="cleanBreads"><a href="javascript:(function(){})();" style="color: red;"><span class="fa fa-trash"></span></a></li>';
            ol.querySelector('li#cleanBreads > a').addEventListener("click", function() {
                if (confirm("진짜로 빵가루를 전부다 청소할까요?")) {
                    localStorage.setItem(itemName, "[]");
                    mw.notify('강제 새로고침하면 지워져 있을겁니다. :)');
                }
            });
           
            return ol;
         }
         }
         ol.appendChild(li);
        var articles = getStorage();
      }
        if(articles.length == 0 || (articles.length != 0 && articles[articles.length - 1] != conf.wgPageName)) articles.push(conf.wgPageName);
      return ol;
         setStorage(articles, conf.wgPageName);
        var breadbar = makeBreadBar(articles, conf.wgPageName);
        var headerAds = document.querySelector(".header-ads");
        headerAds.parentNode.insertBefore(breadbar, headerAds); // 광고 위에 삽입하기
     }
     }
    var articles = getStorage();
    if (articles.length == 0 || (articles.length != 0 && articles[articles.length - 1] != conf.wgPageName)) articles.push(conf.wgPageName);
    setStorage(articles, conf.wgPageName);
    var breadbar = makeBreadBar(articles, conf.wgPageName);
    var contentHeader = document.querySelector(".liberty-content-header");
    contentHeader.prepend(breadbar);
  }
}
}

2023년 12월 30일 (토) 21:39 기준 최신판

/*
 * written By. LiteHell and modified by Utolee90
 * Warning : This script uses localStorage of your browser so BREADCUMB WILL BE DELETED IF YOU CLEAR STORAGE DATA FROM YOUR BROWSER.
 */
if (mw.config.exists("wgIsArticle") && mw.config.exists("wgPageName") && mw.config.exists("wgArticlePath")) {
  var conf = mw.config.get(["wgIsArticle", "wgPageName", "wgArticlePath"]);
  
  mw.loader.load('oojs-ui');
  mw.loader.load('mediawiki.notification');

  if (conf.wgIsArticle) {
    var itemName = "pageBreadcumbs";

    function initStorageIfRequired() {
      if (localStorage.getItem(itemName) == null)
        localStorage.setItem(itemName, "[]");
    }

    function setStorage(value) {
      initStorageIfRequired();
      localStorage.setItem(itemName, JSON.stringify(value.slice(-20)));
    }

    function getStorage() {
      initStorageIfRequired();
      return JSON.parse(localStorage.getItem(itemName));
    }

    function makeBreadBar(arr, active) {
      var ol = document.createElement("ol");
      ol.style.display = 'inline-block';
      ol.style.margin = '0.5em',
      ol.className = "breadcrumb";
      $(ol).append('<li id="cleanBreads" style=""><a href="javascript:(function(){})();" style="color: red;"><span class="fa fa-trash"></span></a></li>');
      ol.querySelector('li#cleanBreads > a').addEventListener("click", function() {
        OO.ui.confirm("진짜로 빵가루를 전부 다 청소할까요?").done(confirmed => {
          if (confirmed) {
            localStorage.setItem(itemName, "[]");
            mw.notification.autoHideSeconds = {'short': 1.5};
            mw.notify('강제 새로고침하면 지워져 있을겁니다. :)');
          }
        });
      });

      // 최근 10개만 역순으로 제작. 중복이 있으면 제외
      var limitCnt = 10;
      var newArr = [];
      var j = 0;
      while (newArr.length < Math.min(limitCnt, arr.length) && j <= arr.length - 1) {
        if (newArr.indexOf(arr[arr.length - 1 - j]) == -1) {
          newArr.push(arr[arr.length - 1 - j]);
        }
        j++;
      }
      for (var i = 0; i < newArr.length; i++) {
        var now = newArr[i];
        var li = document.createElement("li");
        if (now == active) {
          li.className = "active";
          li.textContent = now;
        } else {
          var anchor = document.createElement("a");
          anchor.href = conf.wgArticlePath.replace('$1', now);
          anchor.title = now;
          anchor.textContent = now;
          li.appendChild(anchor);
        }
        ol.appendChild(li);
      }
      return ol;
    }

    var articles = getStorage();
    if (articles.length == 0 || (articles.length != 0 && articles[articles.length - 1] != conf.wgPageName)) articles.push(conf.wgPageName);
    setStorage(articles, conf.wgPageName);
    var breadbar = makeBreadBar(articles, conf.wgPageName);
    var contentHeader = document.querySelector(".liberty-content-header");
    contentHeader.prepend(breadbar);
  }
}