それをさらに見て、表示されるブックマークレットを調べると、全体的なコード構造は次のようになります。
javascript: (function() {
var w = window,
l = w.location,
d = w.document,
s = d.createElement('script'),
e = encodeURIComponent,
x = 'undefined',
u = 'http://www.amazon.co.uk/wishlist/add';
if (typeof s != 'object') l.href = u + '?u=' + e(l) + '&t=' + e(d.title);
function g() {
if (d.readyState && d.readyState != 'complete') {
setTimeout(g, 200);
} else {
// testing if AUWLBook is undefined (AUWL is their global object for it)
// If it is, they add the <script> tag for their JS (variable u)
if (typeof AUWLBook == x) s.setAttribute('src', u + '.js?loc=' + e(l)),
d.body.appendChild(s);
function f() {
// they keep looping through until the Object is finally created
// Then they call the showPopover function which initializes everything
// Builds all the HTML (with JS, etc)
(typeof AUWLBook == x) ? setTimeout(f, 200) : AUWLBook.showPopover();
}
f();
}
}
g();
}())
ご覧のとおり、無名関数が作成されており、ここで行われていることの要点は、スクリプト要素s = d.createElement('script')を現在のドキュメントに作成し、ブックマークレットの残りの部分をロードすることです。 。
// since their global object will be undefined at first they create it
if (typeof AUWLBook == x) s.setAttribute('src', u + '.js?loc=' + e(l)),
d.body.appendChild(s);
href ...の文字列の作成についてはl.href = u + '?u=' + e(l) + '&t=' + e(d.title);
、内部参照用であるため、どのページから来たのかがわかります。ページのタイトルからウィッシュリストアイテムが何であるかを作成していると思います(それは少なくともそれがどのように見えるかです)。
あなたはここで彼らのJSコード全体を見ることができます、彼らはたくさん起こっています:
AmazongブックマークレットJSリンク
しかし、ご覧のとおり、Javascriptから直接ポップアップ全体とDOM要素を構築します。
// (part of the AUWLBook object)
showPopover : function(args){
// etc etc...
// open in window if it can't create a popover
if (!this.canDisplayPopover()) {
window.location.href = 'https://www.amazon.co.uk/wishlist/add' + '?u=' + encodeURIComponent(window.location) + '&t=' + encodeURIComponent(document.title);
return;
}
// Then comes just an insane amount of lines of creating all the elements
floater = shmCreateElement('table', { width: bookmarkletWidth, border: '0', id: 'auwlPopover' }, {position: 'absolute', zIndex: '999999999', width: bookmarkletWidth, tableLayout: 'auto', lineHeight: '100%', borderCollapse: 'collapse'});
shmCreateElementは内部のhtml作成関数です(私はそれをコピーすることをお勧めします)
function shmCreateElement(tagName, props, styles, children) { ... }
つまり、基本的には、JSから完全に表示したいものをすべて用意し、それを現在のページのドキュメントDOMに挿入して、そこに行く必要があると思います。