From b823751272f60a00d6f3ae5043dcac355f8abd9b Mon Sep 17 00:00:00 2001 From: 2Abendsegler <2Abendsegler@users.noreply.github.com> Date: Tue, 21 Nov 2023 01:22:26 +0100 Subject: [PATCH 01/11] [Log Form] Collection - Build JSON from page data "__NEXT_DATA__". - Build isEvent from JSON from page data "__NEXT_DATA__". Default logtypes: - Note that the feature may disappear again and will have to be rebuilt. - Decode cacher name. - Use isEvent from page data. - Check the selected logtype against the possible logtypes. Signature: - Adopt almost all changes from PR of capoaira #2441. - In drafts, add a line break between draft content and signature. - Set focus on logtext in first position. Log templates: - Adjust the size of the logfield. Show length of logtext and word count: - Note that the feature may disappear again and will have to be rebuilt. Show message in case of unsaved log: - Note that the feature may disappear again and will have to be rebuilt. Show additional cache info: - Note: The fields difficulty, terrain, favoritePoints and premiumFavoriteScore are available in page data ("__NEXT_DATA__", props.pageProps.loggable), but the fields have no values. In addition, the watchers are not included there. Therefore, we cannot replace the website reading with this data. Autovisit: - Set action type by log type only if log type changed. Replicate TB-Header to bottom: - Note that the feature may disappear again and will have to be rebuilt. Send Log with F2: - Note that the feature may disappear again and will have to be rebuilt. - Make note in the general area for F2 handling, where the development for the log form is. Others: - Moved a few parameters to the correct place in the config. - Hiding the TBs during inline logging (settings_log_inline_tb) no longer made sense for a long time because it was no longer supported in the new log form. Parameters removed in the coding. --- gc_little_helper_II.user.js | 584 +++++++++++++++++++----------------- 1 file changed, 310 insertions(+), 274 deletions(-) diff --git a/gc_little_helper_II.user.js b/gc_little_helper_II.user.js index 9536a98a..1b791478 100644 --- a/gc_little_helper_II.user.js +++ b/gc_little_helper_II.user.js @@ -338,7 +338,6 @@ var variablesInit = function(c) { c.remove_navi_shop = getValue("remove_navi_shop", false); c.settings_submit_log_button = getValue("settings_submit_log_button", true); c.settings_log_inline = getValue("settings_log_inline", false); - c.settings_log_inline_tb = getValue("settings_log_inline_tb", false); c.settings_log_inline_pmo4basic = getValue("settings_log_inline_pmo4basic", true); c.settings_bookmarks_show = getValue("settings_bookmarks_show", true); c.settings_change_header_layout = getValue("settings_change_header_layout", true); @@ -1455,6 +1454,7 @@ var mainGC = function() { } if (waitCount <= 20) setTimeout(function(){setButtonDescInnerHTMLF2(waitCount, id);}, 100); } + // Send Log from log form is developed in the "Improve log form" area. // Log abschicken (Cache und TB). if (document.location.href.match(/\.com\/(seek|track)\/log\.aspx\?(id|wid|guid|ID|wp|LUID|PLogGuid|code)\=/)) var id = "ctl00_ContentBody_LogBookPanel1_btnSubmitLog"; // PQ speichern | "Bookmark Pocket Query", aus BM PQ erzeugen | PQ zu Routen. @@ -4685,85 +4685,77 @@ var mainGC = function() { try { const isTB = document.location.pathname.match(/^\/live\/(geocache|trackable)\/(?:gc|tb)[a-z0-9]+/i)[1] === 'trackable'; const isDraft = document.location.pathname.match(/^\/live\/geocache\/gc[a-z0-9]+\/draft\/LD[a-z0-9]+\/compose/i); +//xxxx + let pageData = JSON.parse($('#__NEXT_DATA__')[0].innerText).props.pageProps; + const isEvent = pageData.isEvent; let css = ''; - // Signature. - function replacePlaceholderInSignature() { - var id = 'gc-md-editor_md'; - window.addEventListener("load", gclh_setFocus, false); - var finds = global_findCount; - var me = global_me; -//xxxx Function vor GoLive umbenennen. Die Function ist im PR https://github.com/2Abendsegler/GClh/pull/2451. - var owner = decode_innerTextXXXX($('.hidden-by a')[0]); - document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace(/#found_no-?(\d+)?#/ig, (_match, p1) => p1 ? finds - p1 : finds); - finds++; - document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace(/#owner#/ig, owner); - document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace(/#found-?(\d+)?#/ig, (_match, p1) => p1 ? finds - p1 : finds).replace(/#me#/ig, me); - var [aDate, aTime, aDateTime] = getDateTime(); - document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace(/#Date#/ig, aDate).replace(/#Time#/ig, aTime).replace(/#DateTime#/ig, aDateTime); -//xxxx Function vor GoLive umbenennen. Die Function ist im PR https://github.com/2Abendsegler/GClh/pull/2451. - var [aGCTBName, aGCTBLink, aGCTBNameLink, aLogDate] = getGCTBInfoLogFormXXXX(); - document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.replace(/#GCTBName#/ig, aGCTBName).replace(/#GCTBLink#/ig, aGCTBLink).replace(/#GCTBNameLink#/ig, aGCTBNameLink).replace(/#LogDate#/ig, aLogDate); - // Set Cursor to Pos1. - function gclh_setFocus() { - var input = document.getElementById(id); - if (input) { - try { - input.selectionStart = 0; - input.selectionEnd = 0; - input.focus(); - } catch(e) {} - } + // Default logtypes. +//xxxx + function setDefaultLogtype(waitCount) { + if ($('.hidden-by a')[0] && $('.hidden-by a')[0].innerText) { + // Get default logtype. + let logtype = decode_innerText($('.hidden-by a')[0]) == global_me ? settings_default_logtype_owner + : isEvent ? settings_default_logtype_event + : isTB ? settings_default_tb_logtype : settings_default_logtype; + // Return if no logtype is selected or selected logtype is not possible. + if (logtype == -1 || !pageData.logTypes.some(e => e.value == logtype)) return; + // Reload Page with default logtype. + document.location = `${document.location}?logType=${logtype}`; + return; } + waitCount++; if (waitCount <= 1000) setTimeout(function(){setDefaultLogtype(waitCount);}, 10); } + try { + if (!document.location.href.match(/logType=/i) + && ((!isDraft && !isTB && (settings_default_logtype || settings_default_logtype_event || settings_default_logtype_owner)) + || isTB && settings_default_tb_logtype)) { + setDefaultLogtype(0); + } + } catch(e) {gclh_error("Default logtypes in improve log form",e);} + + // Signature. +//xxxx function buildSignature(waitCount) { - // Kein Draft oder Draft mit Signatur. - if ($('#gc-md-editor_md')[0] && !$('#gc-md-editor_md.gclh_signature')[0]) { + function replacePlaceholder(text) { + var id = 'gc-md-editor_md'; + var finds = global_findCount; + var me = global_me; + var owner = decode_innerText($('.hidden-by a')[0]); + text = text.replace(/#found_no-?(\d+)?#/ig, (_match, p1) => p1 ? finds - p1 : finds); + finds++; + text = text.replace(/#owner#/ig, owner).replace(/#me#/ig, me); + text = text.replace(/#found-?(\d+)?#/ig, (_match, p1) => p1 ? finds - p1 : finds); + var [aDate, aTime, aDateTime] = getDateTime(); + text = text.replace(/#Date#/ig, aDate).replace(/#Time#/ig, aTime).replace(/#DateTime#/ig, aDateTime); + var [aGCTBName, aGCTBLink, aGCTBNameLink, aLogDate] = getGCTBInfoLogForm(); + text = text.replace(/#GCTBName#/ig, aGCTBName).replace(/#GCTBLink#/ig, aGCTBLink).replace(/#GCTBNameLink#/ig, aGCTBNameLink).replace(/#LogDate#/ig, aLogDate); + return text; + } + if ($('#gc-md-editor_md')[0] && !$('.gclh_signature')[0]) { if ((!isDraft) || (isDraft && settings_log_signature_on_fieldnotes)) { - var initial_cursor_position = document.getElementById('gc-md-editor_md').selectionEnd; - var logtext = document.getElementById('gc-md-editor_md').value; - var signature = (isTB ? getValue('settings_tb_signature', '') : getValue('settings_log_signature', '')); + let logfield = $('#gc-md-editor_md')[0]; + var logtext = logfield.value; + var signature = getValue("settings_log_signature", ""); if (!logtext.includes(signature.replace(/^\s*/, ''))) { - document.getElementById('gc-md-editor_md').innerHTML += signature; - } - replacePlaceholderInSignature(true); - if (isDraft) { // Draft - // 2 Zeilen sinngemäß von DieBatzen ausgeliehen, um "<" und ">" richtig darzustellen. - var textarea = document.createElement('textarea'); - var value = $('
"; - - html += "
New Log Page Only
"; - html += checkboxy('settings_show_pseudo_as_owner', 'Replace placeholder owner, although there could be a pseudonym') + show_help("If you disable this option, the placeholder for the owner cannot be replaced on the newly designed log page.

If you enable this option, the placeholder for the owner is replaced possibly by the pseudonym of the owner if the real owner is not known.

On the new designed log page there is shown as owner of the cache not the real owner but possibly the pseudonym of the owner for the cache as it is shown in the cache listing under \"A cache by\". The real owner is not available in this cases.") + "
"; - - html += "
Old Log Page Only
"; - html += newParameterOn2; - html += checkboxy('settings_logs_old_fashioned', 'Use old-fashioned log form to log non drafts related logs') + show_help("If you enable this option, you always get the old log form instead of the new one to log non drafts related logs.

Please look also the parameter \"Use old-fashioned log form to log a draft\" in the \"Draft\" area.") + "
"; - html += newParameterVersionSetzen('0.11') + newParameterOff; +//xxxx html += ""; html += " "; html += " "; + html += " "; + html += " "; html += " "; html += " "; + html += " "; + html += " "; + html += " "; html += " "; html += " "; + html += " "; html += " "; html += " "; + html += " "; + html += " "; + html += " "; html += "
Default log type
Default event log type
Default owner log type
Default TB log type
"; + + html += "
New Log Page Only
"; + html += checkboxy('settings_show_pseudo_as_owner', 'Replace placeholder owner, although there could be a pseudonym') + show_help("If you disable this option, the placeholder for the owner cannot be replaced on the newly designed log page.

If you enable this option, the placeholder for the owner is replaced possibly by the pseudonym of the owner if the real owner is not known.

On the new designed log page there is shown as owner of the cache not the real owner but possibly the pseudonym of the owner for the cache as it is shown in the cache listing under \"A cache by\". The real owner is not available in this cases.") + "
"; + + html += "
Old Log Page Only
"; + html += checkboxy('settings_show_bbcode', 'Show smilies') + show_help("This option displays smilies options beside the log form. If you click on a smilie, it is inserted into your log.") + "
"; + html += newParameterOn2; + html += checkboxy('settings_logs_old_fashioned', 'Use old-fashioned log form to log non drafts related logs') + show_help("If you enable this option, you always get the old log form instead of the new one to log non drafts related logs.

Please look also the parameter \"Use old-fashioned log form to log a draft\" in the \"Draft\" area.") + "
"; + html += newParameterVersionSetzen('0.11') + newParameterOff; html += ""; html += "

"+prepareHideable.replace("#id#","mail")+"

"; @@ -16700,7 +16740,6 @@ function getGCTBInfoLogFormXXXX() { setEvForDouPara("settings_show_save_message", "click"); setEvForDouPara("settings_show_vip_list", "click"); setEvForDouPara("settings_process_vup", "click"); - setEvForDouPara("settings_log_inline_tb", "click"); setEvForDouPara("settings_font_color_menu", "input"); setEvForDouPara("settings_font_color_menu", "change"); setEvForDouPara("settings_font_color_submenu", "input"); @@ -16797,8 +16836,6 @@ function getGCTBInfoLogFormXXXX() { setEvForDepPara("settings_process_vupX0", "settings_vup_hide_avatar"); setEvForDepPara("settings_process_vupX0", "settings_vup_hide_log"); setEvForDepPara("settings_vup_hide_avatar", "settings_vup_hide_log"); - setEvForDepPara("settings_log_inline_pmo4basic", "settings_log_inline_tb", false); - setEvForDepPara("settings_log_inline", "settings_log_inline_tb", false); setEvForDepPara("settings_show_mail", "settings_show_mail_in_viplist"); setEvForDepPara("settings_show_mail", "settings_show_mail_in_allmyvips"); setEvForDepPara("settings_show_mail", "settings_mail_icon_new_win"); @@ -17110,7 +17147,6 @@ function getGCTBInfoLogFormXXXX() { 'settings_submit_log_button', 'settings_log_inline', 'settings_log_inline_pmo4basic', - 'settings_log_inline_tb', 'settings_bookmarks_show', 'settings_bookmarks_on_top', 'settings_change_header_layout', From 7fb3fa55b4626889aebd4b84e06484af62e341e6 Mon Sep 17 00:00:00 2001 From: 2Abendsegler <2Abendsegler@users.noreply.github.com> Date: Tue, 21 Nov 2023 08:05:44 +0100 Subject: [PATCH 02/11] Use innerHTML and not value in textarea for changes --- gc_little_helper_II.user.js | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/gc_little_helper_II.user.js b/gc_little_helper_II.user.js index 1b791478..2d107911 100644 --- a/gc_little_helper_II.user.js +++ b/gc_little_helper_II.user.js @@ -4685,13 +4685,11 @@ var mainGC = function() { try { const isTB = document.location.pathname.match(/^\/live\/(geocache|trackable)\/(?:gc|tb)[a-z0-9]+/i)[1] === 'trackable'; const isDraft = document.location.pathname.match(/^\/live\/geocache\/gc[a-z0-9]+\/draft\/LD[a-z0-9]+\/compose/i); -//xxxx let pageData = JSON.parse($('#__NEXT_DATA__')[0].innerText).props.pageProps; const isEvent = pageData.isEvent; let css = ''; // Default logtypes. -//xxxx function setDefaultLogtype(waitCount) { if ($('.hidden-by a')[0] && $('.hidden-by a')[0].innerText) { // Get default logtype. @@ -4715,7 +4713,6 @@ var mainGC = function() { } catch(e) {gclh_error("Default logtypes in improve log form",e);} // Signature. -//xxxx function buildSignature(waitCount) { function replacePlaceholder(text) { var id = 'gc-md-editor_md'; @@ -4739,7 +4736,7 @@ var mainGC = function() { var signature = getValue("settings_log_signature", ""); if (!logtext.includes(signature.replace(/^\s*/, ''))) { let text = (logfield.value != '' ? logfield.value + '\n' : '') + replacePlaceholder(signature); - logfield.value = text; + logfield.innerHTML = text; } if (!$('.gclh_signature')[0]) $('#gc-md-editor_md').addClass('gclh_signature'); logfield.dispatchEvent(new Event('input')); @@ -4755,7 +4752,6 @@ var mainGC = function() { } catch(e) {gclh_error("Signature in improve log form",e);} // Log Templates. -//xxxx function buildLogTemplates(waitCount) { if ($('#log-date')[0] && $('.hidden-by a')[0] && $('div.log-meta-controls')[0] && $('#gc-md-editor_md')[0]) { // Script for insert log template by click. @@ -4850,7 +4846,6 @@ var mainGC = function() { } catch(e) {gclh_error("Log Templates in improve log form",e);} // Save last log text. -//xxxx function saveLastLog() {setValue("last_logtext", $('#gc-md-editor_md')[0].value);} function buildClickForSaveLastLog(waitCount) { if ($('button.submit-button')[0] && !$('button.submit-button.gclh_build_click')[0]) { @@ -4864,7 +4859,6 @@ var mainGC = function() { } catch(e) {gclh_error("Save last log text in improve log form",e);} // Show length of logtext and word count. -//xxxx function buildShowLengthOfLogtext(waitCount) { if ($('#gc-md-editor_md')[0] && !$('.gclh_word_count')[0]) { // Count words. @@ -4885,7 +4879,6 @@ var mainGC = function() { } catch(e) {gclh_error("Show length of logtext in improve log form",e);} // Show message in case of unsaved log. -//xxxx function buildMessUnsavedLog(waitCount) { if ($('.post-button-container')[0] && !$('.gclh_mess_unsaved_log')[0]) { $('.post-button-container').bind('click', () => isSubmit = true); @@ -4908,7 +4901,6 @@ var mainGC = function() { } catch(e) {gclh_error("Show message in case of unsaved log in improve log form",e);} // Show additional cache info. -//xxxx // The fields difficulty, terrain, favoritePoints and premiumFavoriteScore are available in page data ("__NEXT_DATA__", props.pageProps.loggable), // but the fields have no values. In addition, the watchers are not included there. Therefore, we cannot replace the website reading with this data. function outputAddCacheInfo(aci, waitCount) { @@ -5008,7 +5000,6 @@ var mainGC = function() { } catch(e) {gclh_error("Show additional cache info in improve log form",e);} // Auto visit for TBs. -//xxxx function getTbsAV() {return $('ul.tb-list li.tb-item');} function getLogTypeAV() {return $('input[name="logType"]').val();} function getTbCodeAV(tb) {return $(tb).find('.tb-stats dd')[1].innerHTML;}; @@ -5104,7 +5095,6 @@ var mainGC = function() { } catch(e) {gclh_error("Auto visit for TBs in improve log form",e);} // Replicate TB-Header to bottom. -//xxxx function buildTBHeaderToBottom(waitCount) { if ($('.tb-inventory-header')[0] && $('.tb-inventory-header h2')[0] && $('.tb-list')[0] && !$('.tb-inventory-header.gclh_tb_header_bottom')[0]) { $('.tb-list').after('

' + $('.tb-inventory-header h2')[0].innerHTML + '

'); @@ -5128,7 +5118,6 @@ var mainGC = function() { } catch(e) {gclh_error("Replicate TB-Header to bottom in improve log form",e);} // Send Log with F2. -//xxxx function buildSendLogWithF2(waitCount) { if ($('.post-button-container button.gc-button-primary')[0] && !$('.post-button-container button.gc-button-primary')[0].innerHTML.match(/\s\(F2\)/)) { let logBtn = $('.post-button-container button.gc-button-primary')[0]; @@ -14008,7 +13997,6 @@ var mainGC = function() { } // GC/TB Name, GC/TB Link, GC/TB Name Link, preliminary LogDate. -//xxxx function getGCTBInfoLogForm() { var GCTBName = ""; var GCTBLink = ""; var GCTBNameLink = ""; var LogDate = ""; var GCTBName = $('.loggable-header a.geocache-link')[0].innerText; @@ -16125,7 +16113,6 @@ var mainGC = function() { html += newParameterVersionSetzen('0.11') + newParameterOff; html += newParameterOn3; html += content_settings_after_sending_draft_related_log2.replace("settings_drafts_after_new_logging_view_log", "settings_drafts_after_new_logging_view_logX0"); -//xxxx html += checkboxy('settings_after_new_logging_view_log', 'After sending a non draft related log, automatic view log') + show_help(content_settings_after_sending_log + 'If it was not a draft related log, you can enable this option to automatic go to view log page.') + "
"; html += newParameterVersionSetzen('0.12') + newParameterOff; var placeholderDescription = "Possible placeholders:
  #Found# : Your founds + 1 (reduce it with a minus followed by a number)
  #Found_no# : Your founds (reduce it with a minus followed by a number)
  #Me# : Your username
  #Owner# : Username of the owner
  #Date# : Actual date
  #Time# : Actual time in format hh:mm
  #DateTime# : Actual date actual time
  #GCTBName# : GC or TB name
  #GCTBLink# : GC or TB link
  #GCTBNameLink# : GC or TB name as a link
  #LogDate# : Content of field \"Date Logged\"
(Upper and lower case is not required in the placeholders name.)"; @@ -16141,7 +16128,6 @@ var mainGC = function() { html += checkboxy('settings_log_signature_on_fieldnotes', 'Add log signature on drafts logs') + show_help('If this option is disabled, the log signature will not be used by logs coming from drafts. You can use it, if you already have an signature in your drafts.') + "
"; html += " " + "TB log signature" + show_help("The signature is automatically added to your TB logs. You can also use placeholders for variables that will be replaced in the log.") + "   ( Possible placeholders" + show_help(placeholderDescription) + ")
"; html += " " + "
"; -//xxxx html += ""; html += " "; html += "
Default log type "; + html += "    " + " "; html += "
"; - html += ""; + html += ""; } - html += " " + "Cache log signature" + show_help("The signature is automatically added to your logs. You can also use placeholders for variables that will be replaced in the log.") + "   ( Possible placeholders" + show_help(placeholderDescription) + ")
"; - html += " " + "
"; - html += checkboxy('settings_log_signature_on_fieldnotes', 'Add log signature on drafts logs') + show_help('If this option is disabled, the log signature will not be used by logs coming from drafts. You can use it, if you already have an signature in your drafts.') + "
"; - html += " " + "TB log signature" + show_help("The signature is automatically added to your TB logs. You can also use placeholders for variables that will be replaced in the log.") + "   ( Possible placeholders" + show_help(placeholderDescription) + ")
"; - html += " " + "
"; + html += newParameterOn2; + html += checkboxy('settings_add_cache_log_signature', 'Add cache log signature') + show_help("The signature is automatically added to your logs. You can also use placeholders for variables that will be replaced in the log.") + "   ( Possible placeholders" + show_help(placeholderDescription) + ")
"; + html += newParameterVersionSetzen('0.15') + newParameterOff; + html += "    " + "
"; + html += "  " + checkboxy('settings_log_signature_on_fieldnotes', 'Add cache log signature on drafts logs') + show_help('If this option is disabled, the log signature will not be used by logs coming from drafts. You can use it, if you already have an signature in your drafts.') + "
"; + html += newParameterOn2; + html += checkboxy('settings_add_tb_log_signature', 'Add TB log signature') + show_help("The signature is automatically added to your TB logs. You can also use placeholders for variables that will be replaced in the log.") + "   ( Possible placeholders" + show_help(placeholderDescription) + ")
"; + html += newParameterVersionSetzen('0.15') + newParameterOff; + html += "    " + "
"; html += ""; html += " "; html += "
Default log type"; liste += ""; - liste += logicNew; + liste += logic; liste += ""; } var [aGCTBName, aGCTBLink, aGCTBNameLink, aLogDate] = getGCTBInfoLogForm(); @@ -16133,6 +16139,8 @@ var mainGC = function() { html += ""; } html += newParameterOn2; + html += "  " + checkboxy('settings_add_cache_log_signature_as_log_template', 'Add cache log signature as a log template') + "
"; + html += "  " + checkboxy('settings_add_tb_log_signature_as_log_template', 'Add TB log signature as a log template') + "
"; html += checkboxy('settings_add_cache_log_signature', 'Add cache log signature') + show_help("The signature is automatically added to your logs. You can also use placeholders for variables that will be replaced in the log.") + "   ( Possible placeholders" + show_help(placeholderDescription) + ")
"; html += newParameterVersionSetzen('0.15') + newParameterOff; html += "    " + "
"; @@ -16141,6 +16149,8 @@ var mainGC = function() { html += checkboxy('settings_add_tb_log_signature', 'Add TB log signature') + show_help("The signature is automatically added to your TB logs. You can also use placeholders for variables that will be replaced in the log.") + "   ( Possible placeholders" + show_help(placeholderDescription) + ")
"; html += newParameterVersionSetzen('0.15') + newParameterOff; html += "    " + "
"; + html += newParameterOn2; + html += newParameterVersionSetzen('0.15') + newParameterOff; html += ""; html += " "; html += "
Default log type
"; - html += newParameterOn2; - html += newParameterVersionSetzen('0.15') + newParameterOff; html += ""; html += " "; html += "
Default log type