|
/** |
|
* @license |
|
* Copyright (c) 2020 Paul Borm |
|
* |
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
* of this software and associated documentation files (the "Software"), to deal |
|
* in the Software without restriction, including without limitation the rights |
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
* copies of the Software, and to permit persons to whom the Software is |
|
* furnished to do so, subject to the following conditions: |
|
* |
|
* The above copyright notice and this permission notice shall be included in all |
|
* copies or substantial portions of the Software. |
|
* |
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
* SOFTWARE. |
|
*/ |
|
|
|
"use strict"; |
|
|
|
/** |
|
* Name the script. |
|
* @see {@link https://docs.scriptable.app/script/#name} |
|
*/ |
|
Script.name("share-ebay-kleinanzeigen-plain-link"); |
|
|
|
/** |
|
* Plain texts supplied by a share sheet or a shortcut action. |
|
* @see {@link https://docs.scriptable.app/args/} |
|
*/ |
|
const plainText = args.plainTexts[0]; |
|
|
|
/** |
|
* The link you want to share. |
|
* @type {string} |
|
*/ |
|
const sharableLink = EbayKleinanzeigenShare(plainText); |
|
|
|
/** |
|
* Copy `sharableLink` to the iOS pasteboard. |
|
* @see {@link https://docs.scriptable.app/pasteboard/#copystring} |
|
*/ |
|
Pasteboard.copyString(sharableLink); |
|
|
|
/** |
|
* Exit the script. |
|
* @see {@link https://docs.scriptable.app/script/#complete} |
|
*/ |
|
Script.complete(); |
|
|
|
function EbayKleinanzeigenShare(string) { |
|
const urlRegEx = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/; |
|
|
|
const getLinkFromString = (string) => { |
|
if (typeof string !== "string") { |
|
return; |
|
} |
|
const link = urlRegEx.exec(string)[0]; |
|
return link; |
|
}; |
|
|
|
const removeParams = (link) => { |
|
if (typeof link !== "string") { |
|
return; |
|
} |
|
const newLink = link.split("?")[0]; |
|
return newLink; |
|
}; |
|
|
|
const removeArticleName = (link) => { |
|
if (typeof link !== "string") { |
|
return; |
|
} |
|
const name = getArticleName(link); |
|
const newLink = link.replace(`/${name}`, ""); |
|
return newLink; |
|
}; |
|
|
|
const getArticleName = (link) => { |
|
if (typeof link !== "string") { |
|
return; |
|
} |
|
const re = /s-anzeige\/([^\/]*)/; |
|
const name = re.exec(link)[1]; |
|
return name; |
|
}; |
|
|
|
const getSharableLink = (link) => { |
|
if (typeof link !== "string") { |
|
return; |
|
} |
|
|
|
const linkWithParams = getLinkFromString(link); |
|
const linkWithoutParams = removeParams(linkWithParams); |
|
const linkWithoutArticleName = removeArticleName(linkWithoutParams); |
|
const sharableLink = linkWithoutArticleName; |
|
|
|
return sharableLink; |
|
}; |
|
|
|
return getSharableLink(string); |
|
} |
Readme
Setup & Usage
Example
The default output if you want to share/copy an article from the ebay Kleinanzeigen iOS app is the following:
We turn it into just a simple link:
Dislaimer
This small project is in no way connected to eBay Kleinanzeigen GmbH. There are no financial interests behind it.