absPath

absPath = (function(abs, spltr, rplcr){ return function absPath(path, base){
  if(abs.test(path)) return path;
  var [root, rest] = spltr.exec(base);
  if(path[0] !== '/') path = '/'+ rest + path;
  while(path !== (path = path.replace(rplcr, '')));
  return root + path;
}}(/^\w+:\/\/.+/,
   /^\w+:\/\/[^\/]+(?=\/?((?:[^\/]+\/)*))/,
   /(?:\/\.|\/[^\/]+\/\.\.|^\/\.\.)(?=\/|$)/));

if(!this.printp) printp = this.console ? console.log : print;
for(e in test = {
  "absPath('./../../hoge/fuga.jpg', 'http://t.o.p/d0/d1/d2/file.htm')":
    'http://t.o.p/d0/hoge/fuga.jpg',
  "absPath('/hoge/fuga.jpg', 'http://t.o.p/d0/d1/d2/file.htm')":
    'http://t.o.p/hoge/fuga.jpg',
  "absPath('/./././././hoge', 'http://t.o.p/d0/d1/d2/file.htm')":
    'http://t.o.p/hoge',
  "absPath('../hoge/../fuga/../piyo/./', 'http://t.o.p/d0/d1/d2/file.htm')":
    'http://t.o.p/d0/d1/piyo/',
  "absPath('ftp://f.t.p/_', 'http://t.o.p/d0/d1/d2/file.htm')":
    'ftp://f.t.p/_',
  "absPath('/../../../../hoge', 'http://t.o.p/d0/d1/d2/file.htm')":
    'http://t.o.p/hoge',
}) if((x = eval(e)) !== test[e])
  printp(e +'\n ==> '+ uneval(x) +'\n !== '+ uneval(test[e]));
void''

AppJet でごにょごにょする用。微妙な例だがこんな感じで↓

print(html(wget(hm = 'http://opiumhero.web.fc2.com/pict_com_226.html').replace(
  /\b(src=")([^"]+)/g, function(_, a, u){ return a + absPath(u, hm) })));
+

最後のテストケースは変か。ルートの「 .. 」は無視するのが筋かな。

+

そのように変更。