前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >短网址还原的Bookmarklet

短网址还原的Bookmarklet

作者头像
ruanyf
发布2018-04-13 15:58:37
1K0
发布2018-04-13 15:58:37
举报
文章被收录于专栏:阮一峰的网络日志

如今,很多网站提供短网址服务

但是有时候,我们需要知道真实网址是什么。

一个个点击,实在太麻烦。何况在国内,很多网址是点不开的。

我一直希望,有人做一个通用接口,提供所有短网址的还原服务。现在,这样的服务终于出现了,它就是unshort.me

在该网站的首页,输入短网址,点击按钮后就会看到真实网址。更令人满意的是,它还慷慨地提供了调用接口API

今天晚上,我就利用这个接口,写了一个Bookmarklet----"短网址还原(javascript:function unshortMeCallback(o%29{document.title=document.title.substring(7%29;var m;if(o === undefined || o===null %29 {m='%E8%BF%9E%E6%8E%A5%E8%BF%87%E7%A8%8B%E5%87%BA%E9%94%99';}else if(o.resolvedURL && o.resolvedURL!=''%29 {m=decodeURIComponent(o.resolvedURL%29;}else{m='%E8%BF%94%E5%9B%9E%E5%80%BC%E5%87%BA%E9%94%99';}var i=document.createElement('div'%29;i.setAttribute('id','unshortMeWindow'%29;var c = 'left:10px;top:10px;width:350px;';i.style.cssText= 'z-index: 2147483647;position:fixed;'+c+'width:350px;height:135px;border:3px solid #aaa;color:#555;background-color:#fff;text-align:center;margin:0px;font-family:Georgia,Times,serif;font-size:26px;overflow:auto;';document.body.appendChild(i%29;var u='';if(m.substring(0,4%29!='http'%29{u=m;}else if(m.length>90%29{u='<a href="'+m+'">'+m.substring(0,40%29+'...'+m.substring(m.length-40%29+'</a>';}else{u='<a href="'+m+'">'+m+'</a>';}document.getElementById('unshortMeWindow'%29.innerHTML='<div style="text-align: center;width:80%;padding-bottom:1px;margin:15px auto 15px auto;font-size:13px;border-bottom:1px solid #ccc;color:#333;">%E5%8E%9F%E7%BD%91%E5%9D%80</div>'+'<p style="font-size:13px;margin:auto 15px;">'+u+'</p>'+'<p style="font-size:13px;margin-top:15px;"><a onclick="unshortMeClose(%29;">[ %E5%85%B3%E9%97%AD ]</a></p>';return;}function unshortMeClose(%29{var f = document.getElementById('unshortMeWindow'%29;f.style.display='none';f.parentNode.removeChild(f%29;void(0%29;}function unshortMe(%29{var d=document,z=d.createElement('scr'+'ipt'%29,b=d.body;function getSelectedText(%29{if (window.getSelection%29{return window.getSelection(%29.toString(%29;}else if(document.getSelection%29{return document.getSelection(%29;}else if (document.selection%29{return document.selection.createRange(%29.text;}}try{if(!b%29throw(0%29;var t=getSelectedText(%29.replace(/^\s+|\s+$/g,''%29;if(!t%29{alert('%E8%AF%B7%E9%80%89%E6%8B%A9%E7%9F%AD%E7%BD%91%E5%9D%80%EF%BC%81'%29;return;}if(t.length>30||t.indexOf('.'%29==-1||t.indexOf(' '%29>=0%29{alert('%E8%AF%B7%E6%AD%A3%E7%A1%AE%E9%80%89%E6%8B%A9%E7%9F%AD%E7%BD%91%E5%9D%80%EF%BC%81'%29;return;}if(t.substring(0,7%29!='http:\/\/'%29{t='http:\/\/'+t;}d.title='(%E5%A4%8D%E5%8E%9F...%29 '+d.title;z.setAttribute('src','http://api.unshort.me/?r='+encodeURIComponent(t%29+'&t=jsonp&callback=unshortMeCallback'%29;b.appendChild(z%29;}catch(e%29{alert('%E8%AF%B7%E7%AD%89%E5%BE%85%E7%BD%91%E9%A1%B5%E5%8A%A0%E8%BD%BD%E5%AE%8C%E6%AF%95%EF%BC%81'%29;}}unshortMe(%29;void(0%29)"。欢迎安装试用。

它的使用方法很简单。只要在页面上选中短网址,然后点击这个Bookmarklet,就会显示真实网址。

我在Chrome、Firefox 4、IE8下测试,都能正常运行。

(完)

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2011年5月28日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
网站建设
网站建设(Website Design Service,WDS),是帮助您快速搭建企业网站的服务。通过自助模板建站工具及专业设计服务,无需了解代码技术,即可自由拖拽模块,可视化完成网站管理。全功能管理后台操作方便,一次更新,数据多端同步,省时省心。使用网站建设服务,您无需维持技术和设计师团队,即可快速实现网站上线,达到企业数字化转型的目的。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档