Just create a new bookmark in your browser (assuming it's not an IE6) and paste the code from the "bookmarklet" file as the address. Then just open any Marketplace Item page and prss this bookmark.
Last active
February 12, 2020 10:49
-
-
Save norlin/7c44057f1a6b1891f2e34943319ddc15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function()%7B(function()%7Bvar%20container%20%3D%20document.getElementsByClassName('asset-acquire__container')%5B0%5D%3Bif%20(!container)%20%7Breturn%3B%7Dvar%20storage%20%3D%20window.localStorage%3Bif%20(!storage)%20%7Breturn%3B%7Dif%20(window.favoritesBookmarklet)%20%7Breturn%3B%7Dwindow.favoritesBookmarklet%20%3D%20true%3Bvar%20faveList%20%3D%20storage.faveList%20%3F%20JSON.parse(storage.faveList)%20%3A%20%5B%5D%3Bfunction%20makeButton(text%2C%20onClick)%20%7Bvar%20btn%20%3D%20document.createElement('a')%3Bbtn.className%20%3D%20'btn'%3Bbtn.href%20%3D%20'%23'%3Bbtn.innerHTML%20%3D%20text%3Bbtn.style%20%3D%20'margin-top%3A%205px%3B'%3Bbtn.addEventListener('click'%2C%20function(e)%7Be.preventDefault()%3Bif%20(typeof%20onClick%20%3D%3D%20'function')%20%7BonClick()%3B%7D%7D)%3Breturn%20btn%3B%7Dfunction%20save()%20%7Bstorage.faveList%20%3D%20JSON.stringify(faveList)%3BupdateState()%3B%7Dfunction%20add()%20%7BfaveList.push(%7Btitle%3A%20document.title%2Curl%3A%20window.location.href%7D)%3Bsave()%3B%7Dfunction%20get()%20%7Breturn%20faveList.findIndex(function(item)%7Breturn%20item.url%20%3D%20window.location.href%3B%7D)%3B%7Dfunction%20del()%20%7Bvar%20exist%20%3D%20get()%3Bif%20(exist%20%3C%200)%20%7Breturn%3B%7DfaveList.splice(exist%2C%201)%3Bsave()%3B%7Dfunction%20closeFade()%20%7Bvar%20fade%20%3D%20document.getElementById('faveFade')%3Bdocument.body.removeChild(fade)%3B%7Dfunction%20showList()%20%7Bvar%20fade%20%3D%20document.createElement('div')%3Bfade.id%20%3D%20'faveFade'%3Bfade.style%20%3D%20'position%3A%20fixed%3B%20left%3A%200%3B%20top%3A%200%3B%20width%3A%20100%25%3B%20height%3A%20100%25%3B%20background%3A%20rgba(0%2C0%2C0%2C0.2)%3B%20z-index%3A%209999999%3B'%3Bfade.addEventListener('click'%2C%20closeFade)%3Bvar%20list%20%3D%20document.createElement('div')%3Blist.style%20%3D%20'position%3A%20relative%3B%20left%3A%2020px%3B%20top%3A%2020px%3B%20display%3A%20block%3B%20width%3A%2080%25%3B%20height%3A%2060%25%3B%20background%3A%20%23fff%3B%20padding%3A%2010px%3B%20overflow%3A%20hidden%3B%20overflow-y%3A%20auto%3B'%3Bvar%20ul%20%3D%20document.createElement('ul')%3Bul.style%20%3D%20'list-style%3A%20inside'%3BfaveList.forEach(function(item)%7Bvar%20link%20%3D%20document.createElement('a')%3Blink.href%20%3D%20item.url%3Blink.target%20%3D%20'_blank'%3Blink.innerHTML%20%3D%20item.title%3Bvar%20li%20%3D%20document.createElement('li')%3Bli.appendChild(link)%3Bul.appendChild(li)%3B%7D)%3Blist.appendChild(ul)%3Bfade.appendChild(list)%3Bdocument.body.appendChild(fade)%3B%7Dvar%20button%3Bfunction%20updateState()%20%7Bif%20(button)%20%7Bcontainer.removeChild(button)%3B%7Dvar%20current%20%3D%20get()%3Bif%20(current%20%3C%200)%20%7Bbutton%20%3D%20makeButton('Add%20to%20favorites'%2C%20add)%3B%7D%20else%20%7Bbutton%20%3D%20makeButton('Remove%20from%20favorites'%2C%20del)%3B%7Dcontainer.appendChild(button)%3B%7Dvar%20buttonList%20%3D%20makeButton('Show%20favorites'%2C%20showList)%3Bcontainer.appendChild(buttonList)%3BupdateState()%3B%7D(window))%7D)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
// TODO: no time to fix the container selector properly, should work for now | |
var container = document.getElementsByClassName('asset-acquire__container')[0]; | |
if (!container) { | |
return; | |
} | |
var storage = window.localStorage; | |
if (!storage) { | |
return; | |
} | |
if (window.favoritesBookmarklet) { | |
return; | |
} | |
window.favoritesBookmarklet = true; | |
var faveList = storage.faveList ? JSON.parse(storage.faveList) : []; | |
function makeButton(text, onClick) { | |
var btn = document.createElement('a'); | |
btn.className = 'btn'; | |
btn.href = '#'; | |
btn.innerHTML = text; | |
btn.style = 'margin-top: 5px;'; | |
btn.addEventListener('click', function(e){ | |
e.preventDefault(); | |
if (typeof onClick == 'function') { | |
onClick(); | |
} | |
}); | |
return btn; | |
} | |
function save() { | |
storage.faveList = JSON.stringify(faveList); | |
updateState(); | |
} | |
function add() { | |
faveList.push({ | |
title: document.title, | |
url: window.location.href | |
}); | |
save(); | |
} | |
function get() { | |
return faveList.findIndex(function(item){ | |
return item.url = window.location.href; | |
}); | |
} | |
function del() { | |
var exist = get(); | |
if (exist < 0) { | |
return; | |
} | |
faveList.splice(exist, 1); | |
save(); | |
} | |
function closeFade() { | |
var fade = document.getElementById('faveFade'); | |
document.body.removeChild(fade); | |
} | |
function showList() { | |
var fade = document.createElement('div'); | |
fade.id = 'faveFade'; | |
fade.style = 'position: fixed; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.2); z-index: 9999999;'; | |
fade.addEventListener('click', closeFade); | |
var list = document.createElement('div'); | |
list.style = 'position: relative; left: 20px; top: 20px; display: block; width: 80%; height: 60%; background: #fff; padding: 10px; overflow: hidden; overflow-y: auto;'; | |
var ul = document.createElement('ul'); | |
ul.style = 'list-style: inside'; | |
faveList.forEach(function(item){ | |
var link = document.createElement('a'); | |
link.href = item.url; | |
link.target = '_blank'; | |
link.innerHTML = item.title; | |
var li = document.createElement('li'); | |
li.appendChild(link); | |
ul.appendChild(li); | |
}); | |
list.appendChild(ul); | |
fade.appendChild(list); | |
document.body.appendChild(fade); | |
} | |
var button; | |
function updateState() { | |
if (button) { | |
container.removeChild(button); | |
} | |
var current = get(); | |
if (current < 0) { | |
button = makeButton('Add to favorites', add); | |
} else { | |
button = makeButton('Remove from favorites', del); | |
} | |
container.appendChild(button); | |
} | |
var buttonList = makeButton('Show favorites', showList); | |
container.appendChild(buttonList); | |
updateState(); | |
}(window)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment