Difference between revisions of "User:Stevage/common.js"

From Geohashing
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
// <includeonly>
 
// <includeonly>
function waitForWikiEditor(expeditionTemplate){
+
function addToolbarButton(expeditionTemplate) {
  if(typeof $("#wpTextbox1").wikiEditor === "function"){
+
    $('#wpTextbox1').on('wikiEditor-toolbar-doneInitialSections', function () {
      $("#wpTextbox1").wikiEditor("addToToolbar", {
+
        $('#wpTextbox1').wikiEditor('addToToolbar', {
          section: "main",
+
            section: 'main',
          group: "insert",
+
            group: 'insert',
          tools: {
+
            tools: {
              buttonId: {
+
                buttonId: {
                  label: "Expedition template",
+
                    label: 'Expedition template',
                  type: "button",
+
                    type: 'button',
                  icon: "https://geohashing.site/images/thumb/4/4c/Landgeohash.png/24px-Landgeohash.png",
+
                    icon: '/images/thumb/4/4c/Landgeohash.png/24px-Landgeohash.png',
                  action: {
+
                    action: {
                      type: "encapsulate",
+
                        type: 'encapsulate',
                      options: {
+
                        options: {
                          post: expeditionTemplate
+
                            post: expeditionTemplate,
                      }
+
                        },
                  }
+
                    },
              }
+
                },
          }
+
            },
      });
+
        });
  }
+
    });
  else{
 
      setTimeout(function() { waitForWikiEditor(expeditionTemplate)}, 250);
 
  }
 
 
}
 
}
  
const userName = $('.navbar-userloggedin')[0].title.replace(/You are logged in as (.*)\./, '$1')
+
const userName = $('.navbar-userloggedin')[0].title.replace(
 +
    /You are logged in as (.*)\./,
 +
    '$1'
 +
);
  
const expeditionRegex = /\d{4}-\d{2}-\d{2}_-?\d{1,3}_-?\d{1,3}/
+
const expeditionRegex = /\d{4}-\d{2}-\d{2}_-?\d{1,3}_-?\d{1,3}/;
const expeditionMatch = location.toString().match(expeditionRegex)
+
const expeditionMatch = location.toString().match(expeditionRegex);
  
if(expeditionMatch !== null && (mw.config.get(['wgAction']).wgAction === "edit" || mw.config.get(['wgAction']).wgAction === "submit")){
+
if (
  const expeditionData = expeditionMatch[0].split("_")
+
    expeditionMatch !== null &&
  const meetupTemplate = "{{meetup graticule|date=" + expeditionData[0] + "|lat=" + expeditionData[1] + "|lon=" + expeditionData[2] + "}}"
+
    (mw.config.get(['wgAction']).wgAction === 'edit' ||
 
+
        mw.config.get(['wgAction']).wgAction === 'submit')
  const expeditionTemplate = meetupTemplate + "\
+
) {
 +
    const expeditionData = expeditionMatch[0].split('_');
 +
    const date = expeditionData[0];
 +
    const lat = expeditionData[1];
 +
    const lon = expeditionData[2];
 +
    const meetupTemplate =
 +
        '{{meetup graticule|date=' +
 +
        date +
 +
        '|lat=' +
 +
        lat +
 +
        '|lon=' +
 +
        lon +
 +
        '}}';
 +
    // prettier-ignore
 +
    const expeditionTemplate = meetupTemplate + "\
 
\n\
 
\n\
 
==Location==\n\
 
==Location==\n\
Line 44: Line 58:
 
\n\
 
\n\
 
==Photos==\n\
 
==Photos==\n\
<gallery>\n\
+
<gallery heights=\"300px\" mode=\"packed\">\n\
 
</gallery>\n\
 
</gallery>\n\
 
\n\
 
\n\
==Ribbons==\n\
+
==Achievements==\n\
 
{{#vardefine:ribbonwidth|100%}}\n\
 
{{#vardefine:ribbonwidth|100%}}\n\
 +
<!-- delete as appropriate\n\
 +
{{Walk geohash|latitude=" + lat + "|longitude=" + lon + "|date=" + date + "|name=" + userName + "|distance=COMPLETETHIS}}\n\
 +
{{Bicycle geohash|latitude=" + lat + "|longitude=" + lon + "|date=" + date + "|name=" + userName + "|distance=COMPLETETHIS}}\n\
 +
{{Public transport geohash|latitude=" + lat + "|longitude=" + lon + "|date=" + date + "|name=" + userName + "|distance=COMPLETETHIS}}\n\
 +
{{Velociraptor geohash|latitude=" + lat + "|longitude=" + lon + "|date=" + date + "|name=" + userName + "}}\n\
 +
{{Ambassador geohash|latitude=" + lat + "|longitude=" + lon + "|date=" + date + "|name=" + userName + "}}\n\
 +
-->\n\
 
\n\
 
\n\
 
__NOTOC__\n\
 
__NOTOC__\n\
<!--\n\
+
<!-- delete as appropriate\n\
 
[[Category:Expeditions]]\n\
 
[[Category:Expeditions]]\n\
 +
[[Category:Expedition planning]]\n\
 
[[Category:Coordinates reached]]\n\
 
[[Category:Coordinates reached]]\n\
 
[[Category:Coordinates not reached]]\n\
 
[[Category:Coordinates not reached]]\n\
 +
[[Category:Not reached - Did not attempt]]\n\
 
[[Category:Not reached - No public access]]\n\
 
[[Category:Not reached - No public access]]\n\
 
[[Category:Not reached - Mother Nature]]\n\
 
[[Category:Not reached - Mother Nature]]\n\
[[Category:Expeditions with photos]]-->\n\
+
[[Category:Not reached - Technology]]\n\
{{location|DE}}\n\
+
[[Category:Not reached - Time constraints]]\n\
{{user categories|user=" + userName + "}}";
+
[[Category:Expeditions with photos]]\n\
 +
-->\n";
 +
 
 +
    $(document).ready(function () {
 +
        addToolbarButton(expeditionTemplate);
  
  $(document).ready(function() {waitForWikiEditor(expeditionTemplate)});
+
        if ($('#wpTextbox1').val() === '') {
 +
            // Let's just automatically fill a blank page with the template
 +
            $('#wpTextbox1').val(expeditionTemplate);
 +
        }
 +
    });
 
}
 
}
 
// </includeonly>
 
// </includeonly>

Latest revision as of 00:29, 2 August 2023

// <includeonly>
function addToolbarButton(expeditionTemplate) {
    $('#wpTextbox1').on('wikiEditor-toolbar-doneInitialSections', function () {
        $('#wpTextbox1').wikiEditor('addToToolbar', {
            section: 'main',
            group: 'insert',
            tools: {
                buttonId: {
                    label: 'Expedition template',
                    type: 'button',
                    icon: '/images/thumb/4/4c/Landgeohash.png/24px-Landgeohash.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            post: expeditionTemplate,
                        },
                    },
                },
            },
        });
    });
}

const userName = $('.navbar-userloggedin')[0].title.replace(
    /You are logged in as (.*)\./,
    '$1'
);

const expeditionRegex = /\d{4}-\d{2}-\d{2}_-?\d{1,3}_-?\d{1,3}/;
const expeditionMatch = location.toString().match(expeditionRegex);

if (
    expeditionMatch !== null &&
    (mw.config.get(['wgAction']).wgAction === 'edit' ||
        mw.config.get(['wgAction']).wgAction === 'submit')
) {
    const expeditionData = expeditionMatch[0].split('_');
    const date = expeditionData[0];
    const lat = expeditionData[1];
    const lon = expeditionData[2];
    const meetupTemplate =
        '{{meetup graticule|date=' +
        date +
        '|lat=' +
        lat +
        '|lon=' +
        lon +
        '}}';
    // prettier-ignore
    const expeditionTemplate = meetupTemplate + "\
\n\
==Location==\n\
\n\
==Participants==\n\
*[[User:" + userName + "|" + userName + "]]\n\
\n\
==Expedition==\n\
\n\
==Photos==\n\
<gallery heights=\"300px\" mode=\"packed\">\n\
</gallery>\n\
\n\
==Achievements==\n\
{{#vardefine:ribbonwidth|100%}}\n\
<!-- delete as appropriate\n\
{{Walk geohash|latitude=" + lat + "|longitude=" + lon + "|date=" + date + "|name=" + userName + "|distance=COMPLETETHIS}}\n\
{{Bicycle geohash|latitude=" + lat + "|longitude=" + lon + "|date=" + date + "|name=" + userName + "|distance=COMPLETETHIS}}\n\
{{Public transport geohash|latitude=" + lat + "|longitude=" + lon + "|date=" + date + "|name=" + userName + "|distance=COMPLETETHIS}}\n\
{{Velociraptor geohash|latitude=" + lat + "|longitude=" + lon + "|date=" + date + "|name=" + userName + "}}\n\
{{Ambassador geohash|latitude=" + lat + "|longitude=" + lon + "|date=" + date + "|name=" + userName + "}}\n\
-->\n\
\n\
__NOTOC__\n\
<!-- delete as appropriate\n\
[[Category:Expeditions]]\n\
[[Category:Expedition planning]]\n\
[[Category:Coordinates reached]]\n\
[[Category:Coordinates not reached]]\n\
[[Category:Not reached - Did not attempt]]\n\
[[Category:Not reached - No public access]]\n\
[[Category:Not reached - Mother Nature]]\n\
[[Category:Not reached - Technology]]\n\
[[Category:Not reached - Time constraints]]\n\
[[Category:Expeditions with photos]]\n\
-->\n";

    $(document).ready(function () {
        addToolbarButton(expeditionTemplate);

        if ($('#wpTextbox1').val() === '') {
            // Let's just automatically fill a blank page with the template
            $('#wpTextbox1').val(expeditionTemplate);
        }
    });
}
// </includeonly>