// ==UserScript== // @name ShareAlliancePost // @namespace Leitstellenspiel // @version 3.2.2 // @author jalibu, JuMaHo // @include https://www.leitstellenspiel.de/missions/* // ==/UserScript== (() => { 'use strict'; const jumpNext = false; // Set to 'true', to jump to next mission after submitting an alert. const enableKeyboard = true; // Set to 'false', to disable keyboard shortcuts. const shortcutKeys = [17, 68]; // 17= ctrl, 68 = d const defaultPostToChat = true; // Set to 'false', to disable default post in alliance chat. const messages = ['frei zum sammeln', // First entry is default 'Rettungsdienst für %PATIENTS_LEFT% Patienten benötigt', '%ADDRESS%', '%ADDRESS% kein RD, rest frei', 'Offen bis %MY_CUSTOM_TIME%.', '%UNITS_REQUIRED%']; // Create Button and add event listener const initButtons = () => { let btnMarkup = '
'; btnMarkup += ''; btnMarkup += ''; btnMarkup += ''; btnMarkup += ''; btnMarkup += '
'; let optionsBtnMarkup = ''; optionsBtnMarkup += ''; optionsBtnMarkup += ''; $('.alert_next_alliance').parent().append(btnMarkup); $('.alert_notify_alliance').first().parent().prepend(optionsBtnMarkup); $('#openAllianceShareOptions').click(() => { $('#allianceShareOptions').show(); $('#openAllianceShareOptions').hide(); }); $('.customAllianceShareText').click(function() { $('#allianceShareText').val($(this).text()); }); if(jumpNext){ $('.alert_notify_alliance').append(''); } $('.alert_notify_alliance').click(processAllianceShare); }; // Add Keylisteners const initKeys = () => { if(enableKeyboard){ let keys = []; $(document).keydown((e) => { keys.push(e.which); if(keys.length === shortcutKeys.length){ let pressedAll = true; $.each(shortcutKeys, (index, value) =>{ if(keys.indexOf(value) < 0){ pressedAll = false; return; } }); if(pressedAll){ processAllianceShare(); } } }); $(document).keyup((e) => { keys.splice(keys.indexOf(e.which)); }); } }; const processAllianceShare = () => { $('#allianceShareOptions').hide(); $('#openAllianceShareOptions').show(); const sendToAlliance = $('#postToChat').is(':checked') ? 1 : 0; const missionShareLink = $('#mission_alliance_share_btn').attr('href'); const missionId = missionShareLink.replace('/missions/','').replace('/alliance', ''); const csrfToken = $('meta[name="csrf-token"]').attr('content'); const message = $('#allianceShareText').val(); $('.alert_notify_alliance').html('Teilen..'); $.get('/missions/' + missionId + '/alliance' , () => { $('.alert_notify_alliance').html('Chatten..'); $.post( "/mission_replies", {authenticity_token: csrfToken, mission_reply: {alliance_chat: sendToAlliance, content: message, mission_id: missionId}}, (data, status, xhr) => { $('.alert_notify_alliance').html('Alarmieren..'); if(jumpNext){ $('.alert_next').first().click(); } else { $('#mission_alarm_btn').click(); } } ); }); }; const transformMessages = () => { try { // Prepare values for %ADDRESS% and %PATIENTS_LEFT% // Possible inputs 'xy street, 1234 city', '1234 city', '123 city | 2' (where 2 is number of patients) let addressAndPatrientRow = $('.mission_header_info >> small').first().text().trim().split(','); addressAndPatrientRow = addressAndPatrientRow[addressAndPatrientRow.length-1].split('|'); const address = addressAndPatrientRow[0]; const patientsLeft = addressAndPatrientRow.length === 2 ? addressAndPatrientRow[1] : 0; // Adds needed vehicles to selection var unitsRequired = 'Keine weiteren Einheiten benötigt'; if ( $(".alert-danger").length > 0 ) { var unitsRequiredRow = document.getElementsByClassName('alert-danger')[0].innerHTML; unitsRequired = unitsRequiredRow.substr(7, unitsRequiredRow.length-1); } // Prepare values for %MY_CUSTOM_TIME% let customTime = new Date().getHours()+3; customTime = customTime > 24 ? customTime -24 : customTime; for(let i = 0; i