Last active
August 20, 2019 05:33
-
-
Save hluk/b598ab08e00ce9618b33 to your computer and use it in GitHub Desktop.
CopyQ - Tab for URLs with Title and Icon
This file contains hidden or 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
[Command] | |
Automatic=true | |
Command=" | |
copyq: | |
var tabName = '&url' | |
function lower(data) { | |
return str(data).toLowerCase() | |
} | |
function isHtml(reply) { | |
var headers = reply.headers | |
for (var i in headers) { | |
var header = headers[i] | |
if (lower(header[0]) === \"content-type\") | |
return lower(header[1]).indexOf(\"text/html\") === 0 | |
} | |
return false | |
} | |
function curl(url) { | |
reply = networkGet(url) | |
if (isHtml(reply)) | |
return reply.data | |
return \"\" | |
} | |
function grep(content, re) { | |
return content ? (re.exec(content) || [])[1] : '' | |
} | |
function getTitle(content) { | |
return grep(content, /<title>([^<]*)<\\/title>/i) | |
} | |
function getFavicon(content) { | |
var icon = | |
grep( | |
grep(content, /<link([^>]*rel=[\"'](?:shortcut )?icon[\"'][^>]*)/i), | |
/href=[\"']([^\"']*)/i | |
) | |
if (icon && icon[0] === '/') { | |
if (icon[1] === '/') { | |
var i = url.search(/\\/\\//) | |
var protocol = i == -1 ? 'http:' : url.substr(0, i) | |
icon = 'http:' + icon | |
} else { | |
var baseUrl = url.substr(0, url.search(/[^\\/:](\\/|$)/) + 1) | |
icon = baseUrl + icon | |
} | |
} | |
return icon | |
} | |
tab(tabName) | |
var url = str(input()).replace(/\\s.*/, '') | |
if (url === str(read(0))) | |
abort() | |
var content = str(curl(url)) | |
var title = getTitle(content) | |
var icon = getFavicon(content) | |
write( | |
'text/plain', url, | |
'application/x-copyq-item-notes', title || '', | |
'application/x-copyq-item-icon', icon ? curl(icon) : '' | |
)" | |
Icon=\xf0c1 | |
Input=text/plain | |
Match=^https?:// | |
Name=Tab for URLs with Title and Icon |
in version Clipboard Manager testing-10-g45c47562.
doesn't work that well, on and off sort of speak.
Moved to copyq-commands repository.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@hluk Works as expected, but icons are not shown. (using 2.8.0)