Sharelist 自定义脚本&主题

2021-03-29 Views 记录

脚本出自:Sharelist Github Issue - https://github.com/reruin/sharelist/issues/359
样式出自:Cooluc's Blog - https://www.cooluc.com/

面包屑导航

<script>
(function (factory) {
    window["nav"] = factory(window["jQuery"]);
})(function () {
    var nav = {
        init: init,
        item: [],
        css: 'html{scrollbar-color:hsla(0,0%,60%,.3) transparent;scrollbar-width:thin}header{background-color:#fff}header .wrap::-webkit-scrollbar{height:5px}header .wrap::-webkit-scrollbar-thumb{background:#636e72;border-radius:8px}header .wrap::-webkit-scrollbar-track{background:#d6dadc}header .wrap{display:flex;overflow-x:auto;overflow-y:hidden}header .wrap .home{color:#8c8c8c;}.nav{flex:1;display:inline-block;color:initial;font-size:20px;height:56px;line-height:56px;padding-right:16px}.nav ul{display:flex;list-style:none;margin:0;padding:0}.nav li{color:#8c8c8c;white-space:nowrap;text-overflow:ellipsis}.nav li a{color:inherit}.nav li::before{content:"/";margin:0 2px;color:#8c8c8c}.wrap .current{color:#212121!important}',
    }
    return nav;
    function init() {
        $('.nav,.nav-css').remove()
        addStyle()
        nav.item = split(location.pathname)
        render()
    }
    function split(t) {
        return t.substr(1).split('/')
    }
    function addStyle() {
        $('head').append($('<style class="nav-css">').text(nav.css))
    }
    function render() {
        if (nav.item.length == 1 && nav.item[0] == '') {
            return $('.home').addClass('current').css('flex',1)
        }
        var div = $('<div class="nav">'),
            li = [],
            pre = '/'
        $.each(nav.item, function (i, v) {
            if(v == ''){
                return false;
            }
            var a = $('<a>').attr('href', location.origin + pre + v).text(decodeURIComponent(v))
            pre += v + '/'
            li.push($('<li>').html(a))
        });
        li[li.length-1].addClass('current')
        div.append($('<ul>').append(li))
        $('.home').after(div)
    }
});
nav.init();
</script>

无刷新加载

<script src="https://cdn.bootcdn.net/ajax/libs/instantclick/3.1.0/instantclick.min.js" data-no-instant></script>
<script data-no-instant>InstantClick.init("mousedown");</script>

大小、修改时间为空时使用 “-” 显示

<script>
$(".file-size,.file-modified").each(function () {
    "" == $(this).text() && $(this).text("-")
});
</script>

批量复制

<script>
//快捷复制
"use strict";window.jQuery&&!location.pathname.startsWith("/manage")&&$(function(){function e(e){var t=!1,c=document.createElement("textarea"),n=document.activeElement;document.body.appendChild(c),c.value=e,c.focus(),c.setSelectionRange?c.setSelectionRange(0,c.value.length):c.select();try{t=document.execCommand("copy")}catch(e){t=!1}return document.body.removeChild(c),n.focus(),t}var t=[];if($(".list").find("a i:not(.ic-folder)").each(function(){t.push(location.origin+decodeURIComponent($(this).parents("a.clearfix").attr("href").replace(/\?.*/g,"")))}),t.length>0){var c=$('<a><svg class="ic" style="width: 22px;height: 22px;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024"><path d="M662.528 255.488c56.166 0 101.734 45.517 101.734 101.734v457.933c0 56.218-45.568 101.735-101.785 101.735H204.544A101.786 101.786 0 0 1 102.81 815.155V357.222c0-56.217 45.568-101.785 101.734-101.785h457.933z m0 61.03H204.493c-20.48 0-37.837 15.258-40.397 35.584l-0.307 5.12v457.933c0 20.48 15.257 37.837 35.635 40.397l5.12 0.307h457.882c20.53 0 37.888-15.257 40.448-35.635l0.256-5.12v-457.83c0-20.532-15.258-37.888-35.584-40.448l-5.12-0.256zM815.104 102.81c56.269 0 101.786 45.568 101.786 101.734v457.933c0 56.217-45.568 101.785-101.735 101.785v-61.081c20.48 0 37.837-15.258 40.397-35.584l0.307-5.12V204.544c0-20.48-15.257-37.837-35.635-40.397l-5.12-0.307h-457.83c-20.532 0-37.888 15.258-40.448 35.635l-0.256 5.12h-61.133c0-56.217 45.568-101.785 101.785-101.785h457.933z"></path></svg></a>');$(".upload-menu").append(c),c.on("click",function(){e(t.join("\n")),alert("复制成功 共"+t.length+"条")})}});
</script>

iOS自适应暗黑模式 - 自定义样式

<style>
@media (prefers-color-scheme:dark) {
  body {
    background-color:black;
    color:#a1a1a1;
  }
  a {
    color:#b5b5b5;
  }
  header {
    background-color:#000;
    color:#000;
  }
  footer {
    border-top:1px solid #0c0c0c;
  }
  .node-list .node-list__body a:hover {
    background-color:#00000000;
  }
  .auth .sl-input {
    background:#000;
    border:2px solid #2f2f2f;
  }
}
</style>

Theme - sloop

https://github.com/liumingye/sloop