From 0371f92de94144e49f3209b670815e372869e1bb Mon Sep 17 00:00:00 2001 From: Toby Inkster Date: Wed, 18 Jan 2023 21:17:16 +0000 Subject: [PATCH 1/3] Fix broken indentation --- src/share.js | 92 ++++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/share.js b/src/share.js index 89d8462..222f14e 100644 --- a/src/share.js +++ b/src/share.js @@ -16,7 +16,7 @@ navigator.share = navigator.share || (function () { facebook: 'Facebook', skype: 'Skype', pinterest: 'Pinterest', - line: 'LINE', + line: 'LINE', }, cs: { shareTitle: 'Sdílet', @@ -105,8 +105,8 @@ navigator.share = navigator.share || (function () { print: 'Printen', email: 'E-mail', selectSms: 'Selecteer een contact' - }, - sv: { + }, + sv: { shareTitle: 'Dela', cancel: 'Avbryt', copy: 'Kopiera', @@ -161,8 +161,8 @@ navigator.share = navigator.share || (function () { copy: 'நகலெடு', print: 'அச்சிடு', email: 'மின்னஞ்சல்', - selectSms: 'ஒரு தொடர்பைத் தேர்வுசெய்க' - }, + selectSms: 'ஒரு தொடர்பைத் தேர்வுசெய்க' + }, pl: { shareTitle: 'Dzielić', cancel: 'Anuluj', @@ -171,7 +171,7 @@ navigator.share = navigator.share || (function () { email: 'E-mail', selectSms: 'Wybierz kontakt' }, - is: { + is: { shareTitle: 'Deila', cancel: 'Hætta við', copy: 'Afrita', @@ -179,7 +179,7 @@ navigator.share = navigator.share || (function () { email: 'Póstur', selectSms: 'Veldu tengilið' }, - hu: { + hu: { shareTitle: 'Megosztás', cancel: 'Bezárás', copy: 'Másolás', @@ -187,30 +187,30 @@ navigator.share = navigator.share || (function () { email: 'E-mail', selectSms: 'Válasszon egy kontaktot' }, - hi: { - shareTitle: 'शेयर करें', - cancel: 'रद्द करें', - copy: 'कॉपी करें', - print: 'प्रिंट करें', - email: 'ईमेल', - selectSms: 'संपर्क चुनें' - }, - be: { - shareTitle: 'শেয়ার করুন', - cancel: 'বাতিল করুন', - copy: 'কপি করুন', - print: 'প্রিন্ট করুন', - email: 'ই মেইল', - selectSms: 'পরিচিতি নির্বাচন করুন' - }, - ind: { - shareTitle: 'Membagikan', - cancel: 'Membatalkan', - copy: 'Salinan', - print: 'Mencetak', - email: 'Surel', - selectSms: 'Pilih kontak' - } + hi: { + shareTitle: 'शेयर करें', + cancel: 'रद्द करें', + copy: 'कॉपी करें', + print: 'प्रिंट करें', + email: 'ईमेल', + selectSms: 'संपर्क चुनें' + }, + be: { + shareTitle: 'শেয়ার করুন', + cancel: 'বাতিল করুন', + copy: 'কপি করুন', + print: 'প্রিন্ট করুন', + email: 'ই মেইল', + selectSms: 'পরিচিতি নির্বাচন করুন' + }, + ind: { + shareTitle: 'Membagikan', + cancel: 'Membatalkan', + copy: 'Salinan', + print: 'Mencetak', + email: 'Surel', + selectSms: 'Pilih kontak' + } }; let android = navigator.userAgent.match(/Android/i); @@ -234,9 +234,9 @@ navigator.share = navigator.share || (function () { 'twitter': '', 'linkedin': '', 'telegram': '', - 'skype': '', - 'pinterest': '', - 'line': '' + 'skype': '', + 'pinterest': '', + 'line': '' } function appendCSS(content) { @@ -262,7 +262,7 @@ navigator.share = navigator.share || (function () { const { title, url, fbId, hashtags, via, hashtag } = data; - const configs = { + const configs = { ...{ copy: true, print: true, @@ -276,7 +276,7 @@ navigator.share = navigator.share || (function () { telegram: true, skype: true, pinterest: true, - line: true, + line: true, language: 'en' }, ...configurations }; @@ -585,9 +585,9 @@ navigator.share = navigator.share || (function () { break; } case 'email': { - // %0D%0A is newline - const emailText = `${encodeURIComponent(text)}%0D%0A` - const mailto = `mailto:?subject=${title}&body=${emailText}${encodeURIComponent(url)}` + // %0D%0A is newline + const emailText = `${encodeURIComponent(text)}%0D%0A`; + const mailto = `mailto:?subject=${title}&body=${emailText}${encodeURIComponent(url)}`; window.open(mailto); break; } @@ -612,7 +612,7 @@ navigator.share = navigator.share || (function () { 'https://www.facebook.com/sharer/sharer.php?' + 'u=' + encodeURIComponent(url) + '"e=' + encodeURIComponent(text) + - '&hashtag=' + (hashtag || hashtags || '') + '&hashtag=' + (hashtag || hashtags || '') ) break; } @@ -622,8 +622,8 @@ navigator.share = navigator.share || (function () { } case 'twitter': { window.open( - `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}&url=${encodeURIComponent(url)}&hashtags=${hashtags || ''}&via=${via ? encodeURIComponent(via): ''}` - ); + `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}&url=${encodeURIComponent(url)}&hashtags=${hashtags || ''}&via=${via ? encodeURIComponent(via): ''}` + ); break; } case 'linkedin': { @@ -638,10 +638,10 @@ navigator.share = navigator.share || (function () { window.open('https://pinterest.com/pin/create/button/?url=' + encodeURIComponent(url) + '&description=' + encodeURIComponent(text) + '&media=' + image); break; } - case 'line': { - window.open('https://social-plugins.line.me/lineit/share?url=' + encodeURIComponent(url) + '&text=' + encodeURIComponent(text)); - break; - } + case 'line': { + window.open('https://social-plugins.line.me/lineit/share?url=' + encodeURIComponent(url) + '&text=' + encodeURIComponent(text)); + break; + } } resolve(); closeShareUI(); From a8730f689ca7cabbb451773b36927ed8ff59def6 Mon Sep 17 00:00:00 2001 From: Toby Inkster Date: Wed, 18 Jan 2023 21:25:12 +0000 Subject: [PATCH 2/3] Add support for Mastodon Mastodon is a federated social network, so to post on it, the polyfill needs to know which domain the user has an account on. Currently using `prompt()` for this, which isn't the prettiest solution, but it works without adding much extra weight in dependencies. --- src/share.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/share.js b/src/share.js index 222f14e..58c8df5 100644 --- a/src/share.js +++ b/src/share.js @@ -17,6 +17,7 @@ navigator.share = navigator.share || (function () { skype: 'Skype', pinterest: 'Pinterest', line: 'LINE', + mastodon: 'Mastodon', }, cs: { shareTitle: 'Sdílet', @@ -236,7 +237,8 @@ navigator.share = navigator.share || (function () { 'telegram': '', 'skype': '', 'pinterest': '', - 'line': '' + 'line': '', + 'mastodon': '', } function appendCSS(content) { @@ -277,6 +279,7 @@ navigator.share = navigator.share || (function () { skype: true, pinterest: true, line: true, + mastodon: true, language: 'en' }, ...configurations }; @@ -513,6 +516,10 @@ navigator.share = navigator.share || (function () { ${icon.line} ${language.line} +