Website: Load hover preview as needed with JS.

This commit is contained in:
ccd0 2015-03-11 16:30:31 -07:00
parent 1ca069f17e
commit 1c99dc66b6
2 changed files with 25 additions and 15 deletions

View File

@ -16,21 +16,31 @@
</div> </div>
</div> </div>
<a class="screenshot" href="img/screenshot.png"><img src="img/screenshot.png" alt="screenshot"></a> <a class="screenshot" href="img/screenshot.png"><img src="img/screenshot.png" alt="screenshot"></a>
<span class="hover"><img src="img/screenshot.png" alt="preview"></span> <%= content.match(/<\/h1>([^]*)<h2 id="more-information"/)[1] %>
<%=
content
.match(/<\/h1>([^]*)<h2 id="more-information"/)[1]
.replace(/(<a href="([^"]+\.png)">.*?<\/a>)/g, '$1<span class="hover"><img src="$2" alt="preview"></span>')
%>
<script> <script>
var links = document.querySelectorAll('a[href="https://chrome.google.com/webstore/detail/4chan-x/ohnjgmpcibpbafdlkimncjhflgedgpam"]'); function imagePreview() {
for (var i = 0; i < links.length; i++) { this.removeEventListener('mouseover', imagePreview, false);
links[i].addEventListener('click', function(e) { var img = new Image();
if (window.chrome && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey && e.button === 0) { img.src = this.href;
chrome.webstore.install(); img.alt = 'preview';
e.preventDefault(); var span = document.createElement('span');
} span.className = 'hover';
}, false); span.appendChild(img);
this.appendChild(span);
}
function storeInstall(e) {
if (!e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey && e.button === 0) {
chrome.webstore.install();
e.preventDefault();
}
}
for (var i = 0; i < document.links.length; i++) {
var link = document.links[i];
if (/\.png$/.test(link.pathname) && !link.querySelector('.hover')) {
link.addEventListener('mouseover', imagePreview, false);
} else if (window.chrome && link.host === 'chrome.google.com') {
link.addEventListener('click', storeInstall, false);
}
} }
</script> </script>
</body></html> </body></html>

View File

@ -45,7 +45,7 @@ a.screenshot > img {
span.hover { span.hover {
display: none; display: none;
} }
a:hover + span.hover { a:hover > span.hover {
display: block; display: block;
position: fixed; position: fixed;
top: 0; top: 0;