Last active
October 19, 2020 12:47
-
-
Save revenkroz/5aa148c2cae83099a01e02cce6cc951a to your computer and use it in GitHub Desktop.
copilot apple podcast url
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
| (async function() { | |
| const apiUrl = location.href.replace('gqru', 'api'); | |
| const apiResponse = await fetch(apiUrl); | |
| const article = await apiResponse.json(); | |
| const publishUrl = article.metadata?.publishData?.uri || article?._embedded?.publishHistory?.uri; | |
| if (!publishUrl) { | |
| alert('Нет адреса для публикации'); | |
| return; | |
| } | |
| let podcastUrl = prompt('Введите ссылку на подкаст'); | |
| if (!podcastUrl) { | |
| alert('Неправильная ссылка'); | |
| return; | |
| } | |
| podcastUrl = podcastUrl.trim(); | |
| if (/\*\*Слушайте в Apple Podcasts\*\*[^*]*/ug.test(article.body)) { | |
| article.body = article.body.replace( | |
| /\*\*Слушайте в Apple Podcasts\*\*[^*]*/ug, | |
| `**Слушайте в Apple Podcasts**\n\n[](${podcastUrl}){: style="border-bottom:0;display:inline-block;overflow:hidden;background:url("//linkmaker.itunes.apple.com/ru-ru/badge-lrg.svg?releaseDate\\\\\\003D${((new Date).toISOString().split('T')[0])}T00${encodeURIComponent('%3A')}00${encodeURIComponent('%3A')}00Z&kind\\\\\\003Dpodcastepisode&bubble\\\\\\003Dpodcasts") no-repeat;width:165px;height:40px;" }\n\n` | |
| ); | |
| await fetch(apiUrl, { | |
| method: 'PUT', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ | |
| hed: article.hed, | |
| body: article.body, | |
| }), | |
| }); | |
| await fetch(apiUrl + '/publish', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ | |
| uri: publishUrl, | |
| pubDate: article?._embedded?.publishHistory?.pubDate || (new Date).toISOString(), | |
| }), | |
| }); | |
| window.location.reload(); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment