Skip to content

Instantly share code, notes, and snippets.

@robws
Created January 18, 2022 22:09
Show Gist options
  • Save robws/66adb07b97ceafb0fddfd90c9283fa8b to your computer and use it in GitHub Desktop.
Save robws/66adb07b97ceafb0fddfd90c9283fa8b to your computer and use it in GitHub Desktop.
/**
* Convert Page Links to MindMap
* @description
Convert page links to MindMap pasteable text
* @minified
javascript:(function(){function linksToTable(linkList){var tableOut="<table class='financial'><thead><tr><th>Name</th><th>URL</th></tr></thead>";var linkList=Array.from(linkList).map(function(link){return"<tr><td>"+link.innerHTML+"</td><td>"+link.href+"</td></tr>"});return tableOut+"\n"+linkList.join("\n")+"</table>"}function linksToMindMap(linkList){var linkList=Array.from(linkList).map(function(link){return link.innerHTML+"\n "+link.href});return linkList.join("\n")}var htmlText="",thisSelection,g,selectionDiv,i;if(window.getSelection){thisSelection=window.getSelection();if(thisSelection.rangeCount){selectionDiv=document.createElement("div");for(i=0;i<thisSelection.rangeCount;++i){selectionDiv.appendChild(thisSelection.getRangeAt(i).cloneContents())}htmlText=selectionDiv.innerHTML}}else if((thisSelection=document.selection)&&thisSelection.type=="Text"){alert(thisSelection);htmlText=thisSelection.createRange().htmlText}var selectedLinks=selectionDiv.getElementsByTagName("a");if(selectedLinks.length){var newWindow=window.open("","_blank","width=700,height=400").document;newWindow.write("<html><head><title>Forms</title>");newWindow.write("<body>");console.log(linksToTable(selectedLinks));newWindow.write("<textarea rows='20' cols='80'>\n");newWindow.write(linksToMindMap(selectedLinks));newWindow.write("</textarea>");newWindow.write("</body>");newWindow.write("</html>");newWindow.close()}})();
*/
javascript: (function() {
function linksToTable(linkList) {
var tableOut = "<table class='financial'><thead><tr><th>Name</th><th>URL</th></tr></thead>";
var linkList = Array.from(linkList).map(function(link) {
return "<tr><td>" + link.innerHTML + "</td><td>" + link.href + "</td></tr>"
})
return tableOut + "\n" + linkList.join("\n") + "</table>"
}
function linksToMindMap(linkList) {
var linkList = Array.from(linkList).map(function(link) {
return link.innerHTML + "\n " + link.href
})
return linkList.join("\n")
}
var htmlText = '', thisSelection, g, selectionDiv, i;
if (window.getSelection) {
thisSelection = window.getSelection();
if (thisSelection.rangeCount) {
selectionDiv = document.createElement('div');
for (i = 0; i < thisSelection.rangeCount; ++i) {
selectionDiv.appendChild(thisSelection.getRangeAt(i).cloneContents());
}
htmlText = selectionDiv.innerHTML
}
} else if ((thisSelection = document.selection) && thisSelection.type == 'Text') {
alert(thisSelection);
htmlText = thisSelection.createRange().htmlText;
}
var selectedLinks = selectionDiv.getElementsByTagName('a');
if (selectedLinks.length) {
var newWindow = window.open('', '_blank', 'width=700,height=400').document;
newWindow.write("<html><head><title>Forms</title>");
//newWindow.write('<style>p {font-size:14px;} table.financial {width: 600px;font-family:pt sans;}.financial th, .financial td {padding: 7px 10px 10px 10px;}.financial th {text-transform: uppercase; letter-spacing: 0.1em;font-size: 90%;border-bottom: 2px solid #111111;border-top: 1px solid #999;text-align: left;}.financial tr.even {background-color: #efefef;}</style>')
newWindow.write("<body>")
//newWindow.write(linksToTable(selectedLinks));
console.log(linksToTable(selectedLinks))
newWindow.write("<textarea rows='20' cols='80'>\n");
newWindow.write(linksToMindMap(selectedLinks));
newWindow.write("</textarea>")
newWindow.write("</body>")
newWindow.write("</html>")
newWindow.close()
}
}
)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment