Created
October 24, 2017 16:47
-
-
Save otaavioo/44e7269bb67ef5739e090c8ab75273e0 to your computer and use it in GitHub Desktop.
coffeelist
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
var jsonAccentMap = '{"à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","æ":"a","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ß":"s","ù":"u","ú":"u","û":"u","ü":"u","ÿ":"y"}'; | |
var accentRemover = function(s) { | |
var ret = ''; | |
for (var i = 0; i < s.length; i++) { | |
console.log(JSON.parse(jsonAccentMap)); | |
ret += JSON.parse(jsonAccentMap)[s.charAt(i)] || s.charAt(i); | |
} | |
return ret; | |
}; | |
String.prototype.ucfirst = function() { | |
return this.charAt(0).toUpperCase() + this.substr(1); | |
}; | |
var jsonNames = '["amanda","carlos","diogo","eduardo","evelyn","jeniffer","julio","monica","monique","otavio","rafael","rafaela","ray","rose","thuanne","tiago","tiao","vanderlei"]'; | |
var naomarcou = function() { | |
arrNames = JSON.parse(jsonNames); | |
$.each($('.large.circular.label').parent(), function(a, b) { | |
arrNames.forEach(function(c, d) { | |
if (accentRemover($(b).text().trim().toLowerCase()).indexOf(c) !== -1) { | |
arrNames.splice(d, 1); | |
} | |
}); | |
}); | |
arrNames = arrNames.map(function(a) { | |
return a.ucfirst(); | |
}); | |
$message = '<div class="ui warning message transition"><i class="close icon"></i><div class="header">São eles: </div>' + arrNames.join(', ') + '</div>'; | |
$('.ui.container').prepend($message); | |
} | |
var fullNextFridayDate = function() { | |
var date = new Date(), | |
daysTillFriday, | |
fullMonth; | |
daysTillFriday = (5 - date.getDay()); | |
fullDay = ('0' + (date.getDate() + daysTillFriday)).slice(-2); | |
fullMonth = ('0' + (date.getMonth() + 1)).slice(-2); | |
return fullDay + '/' + fullMonth + '/' + date.getFullYear(); | |
}; | |
var getUrl = function() { | |
return window.location.href; | |
}; | |
var createList = function() { | |
if (isAlreadyCreated()) { | |
document.getElementById('data').value = fullNextFridayDate(); | |
$('.ui.blue.labeled.icon.button').click(); | |
} | |
}; | |
var isAlreadyCreated = function() { | |
return $('.ui.blue.selectable.striped.table') | |
.text() | |
.indexOf(fullNextFridayDate()) < 0; | |
}; | |
var isHomePage = function() { | |
return getUrl() === 'http://softers.ml/coffeelist/' || getUrl().indexOf('http://softers.ml/coffeelist/index.php') === 0; | |
}; | |
var isListPage = function() { | |
return getUrl().indexOf('http://softers.ml/coffeelist/list.php') === 0; | |
}; | |
var isLinkShown = function() { | |
return $('.attached .content a').length > 0; | |
}; | |
var redirectToListPage = function() { | |
window.location.href = 'http://softers.ml/coffeelist/list.php'; | |
}; | |
var slackMessageSent = function() { | |
localStorage.setItem('slackMessageSent', true); | |
}; | |
var isSlackMessageSent = function() { | |
return localStorage.getItem('slackMessageSent') !== null; | |
}; | |
var removeSlackMessageSent = function() { | |
return localStorage.removeItem('slackMessageSent'); | |
}; | |
var sendSlackMessage = function() { | |
if (confirm('Enviar mensagem para o slack?')) { | |
var objSlack = { | |
channel: '#todos', | |
username: 'coffeelist', | |
text: '<!channel> A lista do café de amanhã já está criada, cadastre o seu item em: ' + getUrl(), | |
icon_emoji: ':coffee:', | |
} | |
$.ajax({ | |
url: 'https://hooks.slack.com/services/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', | |
type: 'post', | |
dataType: 'JSON', | |
data: 'payload=' + JSON.stringify(objSlack), | |
complete: slackMessageSent | |
}) | |
} | |
}; | |
$(document) | |
.on('click', '.message .close', function() { | |
$(this) | |
.closest('.message') | |
.transition('fade'); | |
}) | |
.ready(function() { | |
if (isHomePage()) { | |
if (isLinkShown() && confirm('Criar lista para amanhã?')) { | |
redirectToListPage(); | |
return; | |
} | |
if (isSlackMessageSent()) { | |
sendSlackMessage(); | |
} | |
} | |
if (isListPage()) { | |
removeSlackMessageSent(); | |
createList(); | |
return; | |
} | |
}); | |
$('.right.menu') | |
.append('<button class="ui red button" data-naomarcou>Quem será que não vai trazer?</button>'); | |
$('[data-naomarcou]') | |
.on('click', naomarcou); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment