Skip to content

Commit

Permalink
absolutize() & links fix, legacy absolutizeOld
Browse files Browse the repository at this point in the history
  • Loading branch information
rostok committed Oct 13, 2021
1 parent e367d84 commit d49e48d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
33 changes: 32 additions & 1 deletion cmdutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,20 @@ CmdUtils.getLocation = function getLocation() {
return "";
};

// returns active tabs origin URL, if avaiable
CmdUtils.getLocationOrigin = function getLocationOrigin() {
if (CmdUtils.active_tab && CmdUtils.active_tab.url) {
try {
var u = new URL(CmdUtils.active_tab.url);
return u.origin;
} catch (e) {
return "";
}
}
else
return "";
};

// opens new tab with provided url
CmdUtils.addTab = function addTab(url) {
var active = true;
Expand Down Expand Up @@ -625,8 +639,25 @@ CmdUtils.url_domain = url_domain;
}( jQuery ));

// changes src and href attributes in jQuery resultset with absoulute urls

(function ( $ ) {
$.fn.absolutize = function(origin) {
if (typeof origin === "undefined" || origin == "") origin = window.origin;
return this.each((i,e)=>{
$(e).attr('href', origin+$(e).prop('pathname'));
if (e.tagName=="IMG") {
try {
var u = new URL(e.src);
$(e).attr('src', origin+u.pathname);
} catch (e) { }
}
});
};
}( jQuery ));

// changes src and href attributes in jQuery resultset with absoulute urls, the old version
(function ( $ ) {
$.fn.absolutize = function( url ) {
$.fn.absolutizeOld = function( url ) {
if (typeof url === "undefined" || url == "") url = window.location;
var others = this.find('[href^="http"],[href^="//:"],[href^="mailto:"],[href^="#"],[href!=""][href],[href^="//"]')
.add('[src^="http"],[src^="//:"],[src^="mailto:"],[src^="#"],[src!=""][src],[src^="//"]');
Expand Down
2 changes: 1 addition & 1 deletion commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ CmdUtils.CreateCommand({
(ret)=>{
arr = arr.concat(
jQuery('a', ret[0])
.absolutize(CmdUtils.getLocation())
.absolutize(CmdUtils.getLocationOrigin())
.map( function() { return jQuery(this).attr('href'); })
.get()
//.filter(s=>s.indexOf(text)>=0)
Expand Down
1 change: 1 addition & 0 deletions scripts/compare-releases.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
if not exist %1 goto error
if not exist %2 goto error

rm -rf a b
7z x -oa %1
7z x -ob %2

Expand Down

0 comments on commit d49e48d

Please sign in to comment.