我正在尝试创建一个类似to this one on 9xbuddy的书签,但我希望它能用于维基百科上的Cite This Page功能。这就是我所拥有的:
javascript:(function(){ window.open('https://en.wikipedia.org/w/index.php?title=Special:CiteThisPage&page=/'+ document.location.href); })();
但如果你试图使用这个东西,它几乎可以工作。问题是页面ID。所以我想知道的是,是否有可能使书签获取或不?
在此先感谢(也运行下面的代码片段以便轻松测试;因此您可以准确地看到使用书签时的结果)。
$(".selectable").click(function() {
$(this).select();
});
$(document).ready(function () {
var selectcounter = 1;
$(".selectable").each(function() {
idja = "selectable" + selectcounter;
$(this).attr('id', idja);
$(this).attr('onclick', 'selectText("' + idja + '")');
selectcounter++;
});
});
function selectText(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
}
}
.selectable {
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
click below text to select it, then drag into bookmarks bar to add as bookmark
<p class="selectable">javascript:(function(){ window.open('https://en.wikipedia.org/w/index.php?title=Special:CiteThisPage&page=/'+ document.location.href); })();</p>
您可以将其用作书签:
javascript:(function(){ window.open('https://en.wikipedia.org/wiki/Special:CiteThisPage?page='+ document.location.href.substr(document.location.href.lastIndexOf('/') + 1)); })();
使用pathname而不是href,然后将/ wiki /替换为空字符串:
document.location.pathname.replace(/^\/wiki\//, ''))
完整书签:
javascript:(function(){ window.open('https://en.wikipedia.org/w/index.php?title=Special:CiteThisPage&page='+ document.location.pathname.replace(/^\/wiki\//, '')); })();