Skip to content

Commit

Permalink
希望能解决掩码添加的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Mapaler committed Oct 10, 2020
1 parent 84b601e commit 74f9ae9
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,39 @@ function save_mask_local() //把掩码设置保存到本地
function load_mask_local() //从空白加载设置
{
var maskstr = GM_getValue("godl-masks");
if (maskstr) //没有设置时就不保存了
var masksCfg;
try {
masksCfg = JSON.parse(maskstr);
} catch (e) {
masksCfg = null;
}

if (!Array.isArray(masksCfg) ||
((parseInt(GM_getValue("new-mask-version"),10) || 1)<curMaskVersion)
) //没有掩码数据,初始化默认配置。
{
addNewMask("普通外链","http://storage.live.com/items/${file.id}:/${file.name}");
addNewMask("最短链接","http://storage.live.com/items/${file.id}");
addNewMask("UBB代码外链图片","[img]http://storage.live.com/items/${file.id}:/${file.name}[/img]");
addNewMask("模板字符串基本使用示例","在OneDrive里查看 ${file.name} 的地址是:${file.webUrl}");
addNewMask("表达式使用示例","${index+1}号文件的尺寸是:${file.size>1024?Math.round(file.size/1024)+\"K\":file.size}B");
addNewMask("自动选择img/mp3 UBB代码","[${file.image?\"img\":(file.audio?\"mp3\":\"file\")}]http://storage.live.com/items/${file.id}:/${file.name}[/${file.image?\"img\":(file.audio?\"mp3\":\"file\")}]");
addNewMask("ES6完整文件尺寸换算示例","${index+1}号文件的尺寸是:${(function(size){const bArr = [\"B\",\"KiB\",\"MiB\",\"GiB\",\"TiB\"];for(let idx=0;idx<bArr.length;idx++){if(idx<bArr.length && size/Math.pow(1024,idx+1)>1)continue;else return (size/Math.pow(1024,idx)).toFixed(2) + \" \" + bArr[idx];}})(file.size)}");
addNewMask("ES6闭包函数示例1","文件的权限是:${(scope=>{switch(scope){case \"anonymous\":return \"所有人\";case \"users\":return \"仅限指定用户\";default:return \"私有\";}})(file.shared?file.shared.scope:null)}");
addNewMask("ES6闭包函数示例2","文件年份:${(createTime=>new Date(createTime).toLocaleString('zh-u-ca-chinese-nu-hanidec',{year:\"numeric\",month:\"long\"}))(file.createdDateTime)}");
addNewMask("第三方 1drv.ws 项目","${file.permissions[0].link.webUrl.replace(\"1drv.ms\",\"1drv.ws\")}");
addNewMask("官方图片下载直连(短期?)","${file[\"@microsoft.graph.downloadUrl\"].replace(/public\.\w+\.files/i,\"public.ch.files\")}");
if (Array.isArray(masksCfg))
{addNewMask("▲以上为版本更新,重新添加的掩码示例","");}
GM_setValue("new-mask-version",curMaskVersion);
}else
{
var masksCfg = JSON.parse(maskstr);
masksCfg.forEach(function(item){
addNewMask(item.name,item.content);
});
}
var mask_index = GM_getValue("godl-mask-index");

var mask_index = parseInt(GM_getValue("godl-mask-index"),10) || 0;
mask_list.selectedIndex = mask_index;
}

Expand Down Expand Up @@ -205,27 +230,6 @@ window.onload = function() //网页加载初始化
mask_content = document.querySelector(".mask-content");
outinfo = document.querySelector(".outinfo");
outcontent = document.querySelector(".outcontent");
var localarr = GM_listValues();
if (!localarr.includes("godl-masks") || !masks.length ||
(parseInt(GM_getValue("new-mask-version"),10) || 1)<curMaskVersion
) //没有掩码数据,初始化默认配置。
{
addNewMask("普通外链","http://storage.live.com/items/${file.id}:/${file.name}");
addNewMask("最短链接","http://storage.live.com/items/${file.id}");
addNewMask("UBB代码外链图片","[img]http://storage.live.com/items/${file.id}:/${file.name}[/img]");
addNewMask("模板字符串基本使用示例","在OneDrive里查看 ${file.name} 的地址是:${file.webUrl}");
addNewMask("表达式使用示例","${index+1}号文件的尺寸是:${file.size>1024?Math.round(file.size/1024)+\"K\":file.size}B");
addNewMask("自动选择img/mp3 UBB代码","[${file.image?\"img\":(file.audio?\"mp3\":\"file\")}]http://storage.live.com/items/${file.id}:/${file.name}[/${file.image?\"img\":(file.audio?\"mp3\":\"file\")}]");
addNewMask("ES6完整文件尺寸换算示例","${index+1}号文件的尺寸是:${(function(size){const bArr = [\"B\",\"KiB\",\"MiB\",\"GiB\",\"TiB\"];for(let idx=0;idx<bArr.length;idx++){if(idx<bArr.length && size/Math.pow(1024,idx+1)>1)continue;else return (size/Math.pow(1024,idx)).toFixed(2) + \" \" + bArr[idx];}})(file.size)}");
addNewMask("ES6闭包函数示例1","文件的权限是:${(scope=>{switch(scope){case \"anonymous\":return \"所有人\";case \"users\":return \"仅限指定用户\";default:return \"私有\";}})(file.shared?file.shared.scope:null)}");
addNewMask("ES6闭包函数示例2","文件年份:${(createTime=>new Date(createTime).toLocaleString('zh-u-ca-chinese-nu-hanidec',{year:\"numeric\",month:\"long\"}))(file.createdDateTime)}");
addNewMask("第三方 1drv.ws 项目","${file.permissions[0].link.webUrl.replace(\"1drv.ms\",\"1drv.ws\")}");
addNewMask("官方图片下载直连(短期?)","${file[\"@microsoft.graph.downloadUrl\"].replace(/public\.\w+\.files/i,\"public.ch.files\")}");
if (localarr.includes("godl-masks"))
{addNewMask("▲以上为版本更新,重新添加的掩码示例","");}
GM_setValue("new-mask-version",curMaskVersion);
}
load_mask_local();

if (location.protocol !="https:" && location.hostname !="localhost" && location.hostname != "")
{
Expand All @@ -235,6 +239,8 @@ window.onload = function() //网页加载初始化
location.protocol = "https:";
}
}

load_mask_local();
}
//OneDrive官方API格式
function launchOneDrivePicker(action = "query"){
Expand Down

0 comments on commit 74f9ae9

Please sign in to comment.