Skip to content

Instantly share code, notes, and snippets.

@santaklouse
Created December 2, 2020 13:56
Show Gist options
  • Select an option

  • Save santaklouse/e77df69ff1bf468dc886cb99a6fb4214 to your computer and use it in GitHub Desktop.

Select an option

Save santaklouse/e77df69ff1bf468dc886cb99a6fb4214 to your computer and use it in GitHub Desktop.
tiny cc url
let getRandomInt = (min, max) => Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min)) + Math.ceil(min));
let tinyCcUrl = (url, custom = '') => {
//need to get it on page
if (!localStorage.getItem('sig')) localStorage.setItem('sig', 'YmNhZGU3OTQ0YmMyNzE0ODBiNWFhZThhZGNjMmQ2ZDg2MjEwYWVlODJmYjQ0ODM3OWVmYzRkMDZiOWRhNTJmZDc3NThmMTcwZWUwNWE4MzhhNWJiOWZlNmRmNjAwMzcwZDJmZGMwZjQ4MDE1MDMzOWM4ZWEzMGI1OWFmYTU3MzU=');
url = encodeURI(url);
sig = encodeURI(localStorage.getItem('sig'));
fetch("https://tiny.cc/tiny/url/create", {
"headers": {
"accept-language": "ru,en;q=0.9,en-US;q=0.8,uk;q=0.7,de;q=0.6,ru-RU;q=0.5",
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"pragma": "no-cache",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest"
},
"referrer": "https://tiny.cc/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": `url=${url}&custom=${custom}&no_stats=1&_signature=${sig}`,
"method": "POST",
"mode": "cors",
"credentials": "include"
}).then(response => response.json())
.then(data => {
if (data.status == -1 && data.message == 'That custom hash is already in use')
return setTimeout(() => tinyCcUrl(url, custom + getRandomInt(0, 1000)));
console.log('Success:', data.short_url);
localStorage.setItem('sig', data._signature||'');
})
.catch((error) => {
console.error('Error:', error);
});
};
tinyCcUrl('https://gateway.ipfs.io/ipfs/QmUb42u9zqzFk2Pe5WBECYd8eVrEmXnFYaguW5uHn77neT/20201202_150950_screenshot.jpg');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment