基于 suowo.cn 官方API制作的 短网址生成 的小书签和快捷指令

小书签版运行截图

安装说明

使用了ES6语法,不兼容IE浏览器
如果需要批量处理,请到官网处理(或采用其他工具, 推荐 Short Url

强烈建议: 安装后申请个人的 key , 并进行手动替换

小书签替换key

IOS捷径替换key

js小书签

小书签代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
javascript:(function() {
'use strict';
const suo_now = true; /*打开时直接压缩window.location.href*/
const suo_api = 'https://suo.im/api.htm';
const suo_key = '5f0729c5b1b63c45d0cb8173@ae63a2ad212f6e56088ab7814732c4c0';
const dq = css => document.querySelector(css);

let suoIm = {
show: function() {
let content = '也可以输入长网址:';
let css = `<style>
.dialog-container {
position: fixed;
top: 0;
width: 40%;
min-width:300px;
margin: 0 auto;
border: 1px solid #ddd;
border-radius: 4px;
background-color: #fff;
font: 14px/1.5 -apple-system,'Microsoft Yahei';
z-index: 99999;
}
.ctrlV-content {padding: 10px;}
.bm-btns {
float: right;
margin-right: 20px;
margin-bottom: 10px;
}
.long-url {
display: block;
width: 98%;
margin-top: 10px;
padding-left: 0.3em;
border: 1px solid #ddd;
border-radius: 4px;
line-height: 28px;
}
.mybtn {
margin-right: 6px;
padding: 0 12px !important;
border: none;
border-radius: 10px;
background: #981a1a;
color: #fff;
letter-spacing: .5em;
text-indent: .5em;
font-size: 14px;
line-height: 27.5px;
}
.mybtn:hover {background-color: #0371df !important;}
#cancel {background: #2d2d2d;}
</style>`;
let html = `
<div class='dialog-container'>
<div class='ctrlV-content'>${content}
<input class='long-url' value='' placeholder='为空则默认为当前网址'>
</div>
<div class='bm-btns'>
<button id='operation' class='mybtn'>${suo_now?'清空':'生成'}</button>
<button id='copy' class='mybtn'>复制</button>
<button id='cancel' class='mybtn'>取消</button>
</div>
</div>
`;
dq('head').insertAdjacentHTML('beforeend', css);
dq('body').insertAdjacentHTML('beforeend', html);
setTimeout(() => {
dq('.long-url').focus();
}, 50);
let screenWidth = window.screen.width;
let _left = (screenWidth - (dq('.dialog-container').offsetWidth)) / 2;
dq('.dialog-container').style.marginLeft = _left + 'px';
suo_now && this.shortUrl(window.location.href);
dq('.bm-btns').addEventListener('click', this.handle);
},

handle: function() {
if (!event.target.id) return;
let url = dq('.long-url').value || window.location.href;
let button = event.target.id;
let oldText = event.target.innerText;
if (button == 'operation'){
if (oldText=='生成') {
suoIm.shortUrl(url);
event.target.innerText = '清空';
} else {
dq('.long-url').value = '';
event.target.innerText = '生成';
}
} else {
if (button == 'copy' && !dq('.long-url').value){
dq('.long-url').setAttribute('placeholder','请先点 [生成] 后再复制');
return;
}
dq('.dialog-container').remove();
dq('style:last-child').remove();
}
},

shortUrl: function(long_url) {
/*
let long_url = 'https://www.bilibili.com/video/BV1EW411u7th?p=1';
*/
this.jsonp({
format:'jsonp',
key: suo_key,
expireDate:'2030-03-31',
url: encodeURIComponent(long_url)
},'jsoncallback');
},

jsonp: function(data, callback) {
let queryString = '?';
for(let k in data){
queryString += k + '=' + data[k] + '&';
}
/*回调函数*/
let _url = suo_api + queryString + 'callback=' + callback;
let head = document.getElementsByTagName('head')[0];
let script = document.createElement('script');
head.appendChild(script);
/*创建jsonp回调函数*/
window[callback] = json => {
dq('.long-url').value = json.url;
dq('.long-url').select();
dq('#copy').addEventListener('click', this.copyText);
head.removeChild(script);
window[callback] = null;
};
/*发送请求*/
script.src = _url;
},

copyText: function() {
let ele = dq('.long-url');
if (navigator.userAgent.match(/ipad|iphone/i)) {
let range = document.createRange();
range.selectNode(ele);
window.getSelection().addRange(range);
document.execCommand('copy');

/*Remove the selections - NOTE: Should use*/
window.getSelection().removeAllRanges();
} else {
ele.focus();
ele.select();
document.execCommand('copy');
}
}
};

suoIm.show();

})();
  • 测试: 短网址
  • 安装: 将上一行的 短网址 拖入到书签栏即可

IOS捷径

地址: https://www.icloud.com/shortcuts/b3197e3d078c4a05a000fef329adabb2

扫码在safari浏览器中打开安装

更多功能

密码短网址

匿名网址

统计分析

请访问官网: https://suo.im/

交流区 温馨提示: 遵纪守法, 友善评论!