Last active
May 5, 2024 21:26
-
-
Save Gesugao-san/d5659de4790590205cba69ead884285a to your computer and use it in GitHub Desktop.
Get all the src and href attributes of a site, insert into console or make markbooklet
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() { | |
'use strict'; | |
var settings = {"tags": ["href", "src"], "protocols": ["http:", "https:"]}; | |
var data = {"detectedLinks": [], "thisProtocolIsOk": false}; | |
for (var i = 0; i < settings['tags'].length; i++) { | |
var srcNodeList = document.querySelectorAll('[' + settings['tags'][i] + ']'); /* srcTags.join('],[') */ | |
for (var ii = 0; ii < srcNodeList.length; ++ii) { | |
data['thisProtocolIsOk'] = false; | |
var item = srcNodeList[ii].getAttribute(settings['tags'][i]); | |
if (item === null) continue; | |
for (var iii = 0; iii < settings['protocols'].length; iii++) { | |
if (item.startsWith(settings['protocols'][iii])) { | |
data['thisProtocolIsOk'] = true; | |
break; | |
} | |
} | |
if (!data['thisProtocolIsOk']) item = document.location['origin'] + item; | |
if (!data['detectedLinks'].includes(item)) | |
data['detectedLinks'].push(item); | |
} | |
} | |
// https://stackoverflow.com/a/46877382/8175291 | |
if (document.documentElement.outerHTML !== null && document.documentElement.outerHTML.hasOwnProperty('match')) { | |
let css_urls1 = document.documentElement.outerHTML.match(/url\(.+(?=\))/g).map(url => url.replace(/url\(/, "")); | |
for (var i = 0; i < css_urls1.length; i++) { | |
if (data['detectedLinks'].includes(css_urls1[i])) continue; | |
data['detectedLinks'].push(css_urls1[i]); | |
} | |
} | |
// https://stackoverflow.com/a/61650413/8175291 | |
let css_urls2 = document.body.getElementsByTagName("style"); | |
for (var i = 0; i < css_urls2.length; i++) { | |
var sheet = css_urls2[i].sheet ? css_urls2[i].sheet : css_urls2[i].styleSheet; | |
var sheet = sheet.CSSRuleList ? sheet.CSSRuleList : sheet.cssRules; | |
if (!sheet) continue; | |
for (var ii = 0; ii < sheet.length; ++ii) { | |
if (sheet[ii].href) | |
if (!data['detectedLinks'].includes(sheet[ii].href)) | |
data['detectedLinks'].push(sheet[ii].href); | |
} | |
} | |
data['detectedLinks'] = data['detectedLinks'].sort(); | |
for (var i = 0; i < data['detectedLinks'].length; i++) { | |
console.log(data['detectedLinks'][i]); | |
} /* https://stackoverflow.com/a/30547087, /a/43467144 */ | |
return; // https://stackoverflow.com/a/35588856/8175291 | |
$.ajax({ | |
url: 'https://web.archive.org/save', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
"Access-Control-Allow-Origin": "*", | |
}, | |
type: 'POST', | |
crossDomain: true, | |
dataType: 'html', | |
data: { | |
}, | |
success: function (result) { | |
console.log("ok"); | |
var content = document.body.textContent || document.body.innerText; | |
var hasText = document.getElementById("saving-msg"); //content.indexOf("saving-msg") !== -1; | |
//if (hasText) | |
// "A snapshot was captured. Visit page: "; "A screen shot was captured. View screen shot: " | |
console.log("is saving:" + document.getElementById("saving-msg").innerHTML.startsWith("Saving...")); | |
}, | |
error: function () { | |
console.log("error"); | |
} | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment