Last active
June 21, 2017 09:03
-
-
Save drugoi/b9a676e6b13e61320223 to your computer and use it in GitHub Desktop.
Отправка ошибок в текстах в Slack
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
let lastSelectedText; | |
const SLACK_HOOK_URL = 'URL TO INCOMING HOOK'; | |
$(document).keydown(e => { | |
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey) { | |
const selectedText = utils.getSelectionText(); | |
if ( | |
lastSelectedText === selectedText || | |
selectedText.replace(/ /g, '') === '' | |
) { | |
console.warn('Текст не выделен или это повторная ошибка'); | |
} else { | |
lastSelectedText = selectedText; | |
const textToFix = { | |
channel: '#canal', // Название канала, куда отправлять ошибки | |
username: 'Ошибкобот', // Название бота | |
text: `Ошибка: «${selectedText}», на странице - <${location.href}>`, // Текст ошибки | |
icon_emoji: ':pencil:' // Иконка бота | |
}; | |
$.post( | |
SLACK_HOOK_URL, | |
{ | |
payload: JSON.stringify(textToFix) | |
}, | |
data => { | |
console.info(data); | |
} | |
); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment