javascript 用于降价网页选择的书签
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 用于降价网页选择的书签相关的知识,希望对你有一定的参考价值。
// Marker, a bookmarklet for Markdownifying webpage selections
// javascript:(function(){var p=document.createElement("p");p.innerHTML="<strong>Loading…</strong>";p.id="loadingp";p.style.padding="20px";p.style.background="#fff";p.style.left="20px";p.style.top=0;p.style.position="fixed";p.style.zIndex="9999999";p.style.opacity=".85";document.body.appendChild(p);document.body.appendChild(document.createElement("script")).src="https://gist.github.com/ttscoff/8078727/raw/Marker.js?x="+(Math.random());})();
(function () {
function callback() {
(function ($) {
var raw, userSelection;
if (window.getSelection) {
// W3C Ranges
userSelection = window.getSelection ();
// Get the range:
if (userSelection.getRangeAt)
var range = userSelection.getRangeAt (0);
else {
var range = document.createRange ();
range.setStart (userSelection.anchorNode, userSelection.anchorOffset);
range.setEnd (userSelection.focusNode, userSelection.focusOffset);
}
// And the HTML:
var clonedSelection = range.cloneContents ();
var div = document.createElement ('div');
div.appendChild (clonedSelection);
raw = div.innerHTML;
} else if (document.selection) {
// Explorer selection, return the HTML
userSelection = document.selection.createRange ();
raw = userSelection.htmlText;
} else {
raw = "";
}
raw = raw.replace(/(src|href)=\"(.*?)\"/g, function(match, p1, p2, offset, string) {
if (!/^http/.test(p2)) {
if (/^\//.test(p2))
var baselink = window.location.protocol + "//" + window.location.hostname;
else
var baselink = window.location.href.split("/").slice(0,-1).join("/") + "/";
return [p1,"=\"",baselink+p2,"\""].join('');
}
return match;
})
var showFrame = "0";
if (window.markerShowFrame !== undefined) {
switch (window.markerShowFrame) {
case 0:
case false: showFrame = "0"; break;
default: showFrame = "1";
}
}
var $form = $("<form>").attr("method", "post").attr("action", "http://heckyesmarkdown.com/go/")
.append($("<input name=html>").val(encodeURIComponent(raw)))
.append($("<input name=read>").val("0"))
.append($("<input name=output>").val("md"))
.append($("<input name=showframe>").val(showFrame))
.appendTo('body');
$form.submit();
})(jQuery.noConflict(true))
}
var s = document.createElement("script");
s.src = "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
if (s.addEventListener) {
s.addEventListener("load", callback, false)
} else if (s.readyState) {
s.onreadystatechange = callback
}
document.body.appendChild(s);
})();
以上是关于javascript 用于降价网页选择的书签的主要内容,如果未能解决你的问题,请参考以下文章
javascript书签复制网页标题和链接
javascript [一键订阅Inoreader书签脚本]可用于在浏览器创建一个“一键订阅至Inoreader”的脚本书签按钮
javascript 用于从书签中加载外部脚本的简单代码段。
如何从网页在主屏幕上添加 android 书签?
用于打开新窗口的书签将当前窗口转发到 [对象窗口]?
用于 UNIX 系统的较少样式的降价查看器