Created
March 22, 2020 06:37
-
-
Save AlexeyNik/db50798f217e78368fdfb733ea07d996 to your computer and use it in GitHub Desktop.
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
https://forum.rudtp.ru/threads/skript-dlja-giperssylki-na-url-iz-klipborda.75166/ | |
function clipboard2hyperlink () { | |
if (!app.documents.length) { | |
return false; | |
} | |
var doc = app.activeDocument; | |
if (app.selection.length != 1 || !app.selection[0].hasOwnProperty('characters')) { | |
return false; | |
} | |
var text = app.selection[0].getElements()[0]; | |
var shadow = doc.pages[0].textFrames.add(undefined, undefined, undefined, {geometricBounds: [0,0,1,1]}); | |
shadow.parentStory.insertionPoints[0].select(); | |
app.paste(); | |
if ((/[\w]/).test(shadow.parentStory.contents.toString())) { | |
while (hiperlinkSources = text.findHyperlinks(), hiperlinkSources.length) { | |
hiperlinkSources[hiperlinkSources.length - 1].remove(); | |
} | |
var source = doc.hyperlinkTextSources.add(text); | |
var dest = doc.hyperlinkURLDestinations.add(shadow.parentStory.contents.toString()); | |
var hyperlink = doc.hyperlinks.add(source, dest); | |
if (charStyle = doc.characterStyles.itemByName('Hyperlink'), charStyle.isValid) { | |
source.appliedCharacterStyle = charStyle; | |
} | |
} | |
shadow.remove(); | |
} | |
app.doScript(clipboard2hyperlink, ScriptLanguage.JAVASCRIPT, [], UndoModes.FAST_ENTIRE_SCRIPT, 'Hyperlink by Clipboard'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment