javascript customize.js

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript customize.js相关的知识,希望对你有一定的参考价值。

<link href="https://fonts.googleapis.com/css?family=Nunito:400,700" rel="stylesheet">
<script  type="text/discourse-plugin" version="0.4">

    function mapCategotries(category){
        var CATEGORIES = {
             'convert-sorted-list-to-binary-search-tr-solved' : 'convert-sorted-list-to-binary-search-tree',
             'construct-binary-tree-from-inorder-and-solved': 'construct-binary-tree-from-inorder-and-preorder',
             'binary-tree-from-inorder-and-postorder-solved' : 'construct-binary-tree-from-inorder-and-postorder',
             'minimum-characters-required-to-make-a-s-solved': 'minimum-characters-required-to-make-a-string-palindromic',
             'largest-distance-between-nodes-of-a-tre-solved': 'largest-distance-between-nodes-of-a-tree',
             'possibility-of-finishing-all-courses-gi-solved': 'possibility-of-finishing-all-courses-given-prerequisites',
             'numbers-of-length-n-and-value-less-than-solved': 'numbers-of-length-n-and-value-less-than-k',
             'largest-area-of-rectangle-with-permutat-solved' : 'largest-area-of-rectangle-with-permutations',
             'convert-sorted-list-to-binary-search-tr-unsolved' : 'convert-sorted-list-to-binary-search-tree',
             'construct-binary-tree-from-inorder-and-unsolved': 'construct-binary-tree-from-inorder-and-preorder',
             'binary-tree-from-inorder-and-postorder-unsolved' : 'construct-binary-tree-from-inorder-and-postorder',
             'minimum-characters-required-to-make-a-s-unsolved': 'minimum-characters-required-to-make-a-string-palindromic',
             'largest-distance-between-nodes-of-a-tre-unsolved': 'largest-distance-between-nodes-of-a-tree',
             'possibility-of-finishing-all-courses-gi-unsolved': 'possibility-of-finishing-all-courses-given-prerequisites',
             'numbers-of-length-n-and-value-less-than-unsolved': 'numbers-of-length-n-and-value-less-than-k',
             'largest-area-of-rectangle-with-permutat-unsolved' : 'largest-area-of-rectangle-with-permutations'
        }
        return CATEGORIES[category];
    }




    function modifyUrl(url){
        var index = url.indexOf('/c/');
        var str = url.substr(index + 25);
        if(mapCategotries(str)){
             return "https://www.interviewbit.com/problems/" + mapCategotries(str);
        } else {
            var newStr, i;
            if( (i = str.indexOf('-solved')) != -1){
                newStr = str.substr(0,i);
            } else if ( (i = str.indexOf('-unsolved') ) != -1 ) {
                newStr = str.substr(0,i);
            } else {
                newStr = str;
            }
            return "https://www.interviewbit.com/problems/" + newStr;
        }
    }

    function getUrl(){
        var url = location.pathname;
        if( url.indexOf('/c/') != -1 ){
            return modifyUrl(url);
        } else if ( url.indexOf('/t/') != -1 ) {
            var url = document.querySelectorAll('.topic-category a')[1].href
            return modifyUrl(url);
        } else {
            return "";
        }
    }
    function doLink(){
        var topmenu = document.getElementsByClassName("category-breadcrumb")[0] || document.getElementsByClassName("topic-category")[0];
        if(topmenu==null || location.pathname == "/" || location.pathname == "/posted" || location.pathname == "/categories" || 
        location.pathname == "/new" || location.pathname == "/latest" || location.pathname == "/unread" 
        || location.pathname == "/top" || location.pathname == '/top/all' ||  location.pathname == '/top/yearly' || location.pathname == '/top/quarterly' 
        || location.pathname == '/top/monthly' || location.pathname.indexOf('/tags/') != -1 || location.pathname == '/top/weekly' || location.pathname == '/top/daily'){
            return;
        }
        if(location.pathname == '/c/announcements' || location.pathname == '/c/interviewbit-problems' || location.pathname == '/c/uncategorizeds' 
        || location.pathname == '/c/interview-experiences' || location.pathname == '/c/uncategorized' ||  location.pathname == '/c/interview-problems')
        return;
        
        if(topmenu.getElementsByTagName("li").length> 2 && location.pathname.indexOf('/c/') != -1  ){
            return;
        }
        
        if($('.title-wrapper a.badge-wrapper')[0].href.split('/').pop() == 'interview-problems' ){
            return;
        }
        
        if(topmenu.getElementsByTagName("li").length> 0 && location.pathname.indexOf('/t/') != -1){
            return;
        }
         var button_site=document.createElement("li");
    	 button_site.className = "ember-view bullet";
    	 var link = document.createElement("a");
    	 var p_url = getUrl(); 
    	 link.href = p_url;
    	 link.target = '_blank';
    	 link.className = "dropdown-header";
    	 link.className += " problem_page_button";
    	 link.title = "My Site";
    	 link.appendChild(document.createTextNode("Problem Page"));
    	 button_site.appendChild(link);
         topmenu.insertBefore(button_site, topmenu.getElementsByTagName("li")[0] || topmenu.getElementsByTagName("a")[0]);
    }
    

window.onload = function() {
    doLink();
    var timer = setInterval( doLink , 1000);
};

var widgetObj = function(helper)
{ 
    return helper.h('ul.external_links',[
    helper.h('li', [
        helper.h('a.header-items', {
            href:'https://www.interviewbit.com/dashboard',
            title: 'Practice'
        }, 'Practice')
        ]),
        helper.h('li', [
        helper.h('a.header-items', {
            href:'https://www.interviewbit.com/referrals',
            title: 'Referral'
        }, 'Referrals')
        ]),
        helper.h('li', [
        helper.h('a.header-items', {
            href:'https://www.interviewbit.com/contribute',
            title: 'Contribute'
        }, 'Contribute')
        ])
    ]);
}
api.decorateWidget('home-logo:after', helper => {
    return widgetObj(helper);
});
    
</script>

以上是关于javascript customize.js的主要内容,如果未能解决你的问题,请参考以下文章

javascript的题。

javascript JavaScript isset()等效: - JavaScript

JavaScript 使用JavaScript更改CSS(JavaScript)

JavaScript之基础-1 JavaScript(概述基础语法)

前端基础-JavaScript的基本概述和语法

JavaScript