Upon guardando più, e ispezionare il bookmarklet che appare, qui è la struttura complessiva del codice:
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();
}())
Come si può vedere si crea una funzione anonima, e il jist di ciò che sta accadendo qui è che stanno creando un elemento di script s = d.createElement ('script'), nel documento corrente che carica il resto del bookmarklet.
// 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);
Per quanto riguarda l'edificio stringa per il href ... Sembra l.href = u + '?u=' + e(l) + '&t=' + e(d.title);
è per il loro riferimento interno in modo da sapere quale pagina/etc sei venuto, sto supponendo che stanno costruendo che cosa l'articolo Lista dei desideri è dal titolo della pagina (è quello che sembra almeno).
Si può vedere tutto il loro codice JS qui, hanno un bel po 'in corso: Amazong Bookmarklet JS Link
Ma come si può vedere che costruire l'intero comparsa & i DOMelements direttamente dal JavaScript:
// (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 essendo la loro funzione interna creazione html (mi piacerebbe def suggerisco copiandolo)
function shmCreateElement(tagName, props, styles, children) { ... }
Quindi suppongo che in pratica sia necessario avere tutto ciò che si desidera apparire completamente proveniente da JS, averlo iniettato nel documento DOM attuale, e così via.
State chiedendo un modo per visualizzare una finestra del browser, senza alcuna finestra di Chrome? Ho paura che potrebbe essere al di là di tutto ciò che puoi fare con javascript. – Radu
@Radu si, esattamente questo, domanda modificata con l'esempio –
Grazie .... [ora questa pagina è nella mia lista dei desideri :-P] (http://www.amazon.co.uk/registry/wishlist/2EU2F4LZYVZI7) – Neal