Skip to content

Instantly share code, notes, and snippets.

@hluk hluk/CopyQ - URLs.ini
Last active Aug 20, 2019

Embed
What would you like to do?
CopyQ - Tab for URLs with Title and Icon
[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
@nsomar

This comment has been minimized.

Copy link

commented Apr 25, 2016

This looks super cool.
How do I add this to copyq?

@ousui

This comment has been minimized.

Copy link

commented Jul 26, 2016

@oarrabi
copy this and open copyq main windows, then press F6, and ctrl+v

@pihentagy

This comment has been minimized.

Copy link

commented Nov 30, 2016

@hluk Works as expected, but icons are not shown. (using 2.8.0)

@royharoush

This comment has been minimized.

Copy link

commented Feb 20, 2017

in version Clipboard Manager testing-10-g45c47562.
doesn't work that well, on and off sort of speak.

@hluk

This comment has been minimized.

Copy link
Owner Author

commented Mar 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.