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

From Geohashing
(stolen again)
m (rm location)
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
// <includeonly>
 +
function waitForWikiEditor(){
 +
    if(typeof $("#wpTextbox1").wikiEditor === "function"){
 +
        $("#wpTextbox1").wikiEditor("addToToolbar", {
 +
            section: "main",
 +
            group: "insert",
 +
            tools: {
 +
                buttonId: {
 +
                    label: "Expedition template",
 +
                    type: "button",
 +
                    icon: "https://geohashing.site/images/thumb/4/4c/Landgeohash.png/22px-Landgeohash.png",
 +
                    action: {
 +
                        type: "encapsulate",
 +
                        options: {
 +
                            post: expeditionTemplate
 +
                        }
 +
                    }
 +
                }
 +
            }
 +
        });
 +
    }
 +
    else{
 +
        setTimeout(waitForWikiEditor, 250);
 +
    }
 +
}
 +
 
var expeditionRegex = /\d{4}-\d{2}-\d{2}_-?\d{1,3}_-?\d{1,3}/
 
var expeditionRegex = /\d{4}-\d{2}-\d{2}_-?\d{1,3}_-?\d{1,3}/
var expeditionData = location.toString().match(expeditionRegex)[0].split("_")
+
var expeditionMatch = location.toString().match(expeditionRegex)
var meetupTemplate = "{{meetup graticule\n\
+
 
|lat=" + expeditionData[1] + "\n\
+
if(expeditionMatch !== null && (mw.config.get(['wgAction']).wgAction === "edit" || mw.config.get(['wgAction']).wgAction === "submit")){
|lon=" + expeditionData[2] + "\n\
+
    var expeditionData = expeditionMatch[0].split("_")
|date=" + expeditionData[0] + "\n\
+
    var ribbonsTemplate = "\n\{{land geohash|latitude=" + expeditionData[1] + "|longitude=" + expeditionData[2] + "|date=" + expeditionData[0] + "}}\n\{{Public transport geohash|latitude=" + expeditionData[1] + "|longitude=" + expeditionData[2] + "|date=" + expeditionData[0] + "| busline=  }}\n\<!--{{No trespassing|latitude=" + expeditionData[1] + "|longitude=" + expeditionData[2] + "|date=" + expeditionData[0] + "}}-->"
}}"
+
    var meetupTemplate = "{{meetup graticule|date=" + expeditionData[0] + "|lat=" + expeditionData[1] + "|lon=" + expeditionData[2] + "|graticule_link=}}"
  
var expeditionTemplate = meetupTemplate + "\n\
+
    var expeditionTemplate = meetupTemplate + "\n\
__NOTOC__\n\
+
==Location==\n\
== Location ==\n\
 
<!-- where you've surveyed the hash to be -->\n\
 
\n\
 
== Participants ==\n\
 
<!-- who attended: If you link to your wiki user name in this section, your expedition will be picked up by the various statistics generated for geohashing. You may use three tildes ~ as a shortcut to automatically insert the user signature of the account you are editing with.\n\
 
-->\n\
 
\n\
 
== Plans ==\n\
 
<!-- what were the original plans -->\n\
 
 
\n\
 
\n\
== Expedition ==\n\
+
==Participants==\n\
<!-- how it all turned out. your narrative goes here. -->\n\
+
*[[User:Leidenfrost|Leidenfrost]]\n\
 +
*<!--[[User:π π π|π π π]]-->\n\
 
\n\
 
\n\
== Tracklog ==\n\
+
==Expedition==\n\
<!-- if your GPS device keeps a log, you may post a link here -->\n\
 
 
\n\
 
\n\
== Photos == \n\
+
==Photos==\n\
<!-- Insert pictures between the gallery tags using the following format: \n\
+
<gallery>\n\
Image:2020-##-## ## ## Alpha.jpg | Witty Comment\n\
 
-->\n\
 
<gallery perrow='5'>\n\
 
 
</gallery>\n\
 
</gallery>\n\
 
\n\
 
\n\
== Achievements ==\n\
+
==Ribbons==\n\
{{#vardefine:ribbonwidth|100%}}\n\
+
{{#vardefine:ribbonwidth|100%}}" + ribbonsTemplate + "\n\
<!-- Add any achievement ribbons you earned below, or remove this section -->\n\
 
 
\n\
 
\n\
<!-- =============== USEFUL CATEGORIES FOLLOW ================\n\
+
__NOTOC__\n\
Delete the next line ONLY if you have chosen the appropriate categories below. If you are unsure, don't worry. People will read your report and help you with the classification. -->\n\
+
<!--\n\
[[Category:New report]]\n\
 
\n\
 
<!-- ==REQUEST FOR TWITTER BOT== Please leave either the New report or the Expedition planning category in as long as you work on it. This helps the twitter bot a lot with announcing the right outcome at the right moment. -->\n\
 
\n\
 
<!-- Potential categories. Please include all the ones appropriate to your expedition -->\n\
 
<!-- If this is a planning page:\n\
 
[[Category:Expedition planning]]\n\
 
-->\n\
 
\n\
 
<!-- If all those plans are never acted upon, change [[Category:Expedition planning]] to [[Category:Not reached - Did not attempt]]. -->\n\
 
\n\
 
<!-- An actual expedition:\n\
 
 
[[Category:Expeditions]]\n\
 
[[Category:Expeditions]]\n\
-- and one or more of --\n\
 
[[Category:Expeditions with photos]]\n\
 
[[Category:Expeditions with videos]]\n\
 
[[Category:Expedition without GPS]]\n\
 
-->\n\
 
\n\
 
<!-- if you reached your coords: \n\
 
 
[[Category:Coordinates reached]]\n\
 
[[Category:Coordinates reached]]\n\
\n\
 
\n\
 
--><!-- or if you failed :(\n\
 
 
[[Category:Coordinates not reached]]\n\
 
[[Category:Coordinates not reached]]\n\
-- and a reason --\n\
+
[[Category:Not reached - No public access]]\n\
When there is a natural obstacle between you and the target:\n\
 
 
[[Category:Not reached - Mother Nature]]\n\
 
[[Category:Not reached - Mother Nature]]\n\
  \n\
+
[[Category:Expeditions with photos]]-->\n\
When there is a man-made obstacle between you and the target:\n\
 
[[Category:Not reached - No public access]]\n\
 
\n\
 
When you failed get your GPS, car, bike or such to work:\n\
 
[[Category:Not reached - Technology]]\n\
 
    \n\
 
When you went to an alternate location instead of the actual geohash:\n\
 
[[Category:Not reached - Attended alternate location]]\n\
 
\n\
 
(Don't forget to delete this final close comment marker) --> \n\
 
 
";
 
";
  
$("#wpTextbox1").wikiEditor("addToToolbar", {
+
    $(document).ready(waitForWikiEditor);
    section: "main",
+
}
    group: "insert",
+
// </includeonly>
    tools: {
 
        buttonId: {
 
            label: "Expedition template",
 
            type: "button",
 
            icon: "https://geohashing.site/images/thumb/4/4c/Landgeohash.png/22px-Landgeohash.png",
 
            action: {
 
                type: "encapsulate",
 
                options: {
 
                    post: expeditionTemplate
 
                }
 
            }
 
        }
 
    }
 
});
 

Latest revision as of 13:38, 28 August 2022

// <includeonly>
function waitForWikiEditor(){
    if(typeof $("#wpTextbox1").wikiEditor === "function"){
        $("#wpTextbox1").wikiEditor("addToToolbar", {
            section: "main",
            group: "insert",
            tools: {
                buttonId: {
                    label: "Expedition template",
                    type: "button",
                    icon: "https://geohashing.site/images/thumb/4/4c/Landgeohash.png/22px-Landgeohash.png",
                    action: {
                        type: "encapsulate",
                        options: {
                            post: expeditionTemplate
                        }
                    }
                }
            }
        });
    }
    else{
        setTimeout(waitForWikiEditor, 250);
    }
}

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

if(expeditionMatch !== null && (mw.config.get(['wgAction']).wgAction === "edit" || mw.config.get(['wgAction']).wgAction === "submit")){
    var expeditionData = expeditionMatch[0].split("_")
    var ribbonsTemplate = "\n\{{land geohash|latitude=" + expeditionData[1] + "|longitude=" + expeditionData[2] + "|date=" + expeditionData[0] + "}}\n\{{Public transport geohash|latitude=" + expeditionData[1] + "|longitude=" + expeditionData[2] + "|date=" + expeditionData[0] + "| busline=  }}\n\<!--{{No trespassing|latitude=" + expeditionData[1] + "|longitude=" + expeditionData[2] + "|date=" + expeditionData[0] + "}}-->"
    var meetupTemplate = "{{meetup graticule|date=" + expeditionData[0] + "|lat=" + expeditionData[1] + "|lon=" + expeditionData[2] + "|graticule_link=}}"

    var expeditionTemplate = meetupTemplate + "\n\
==Location==\n\
\n\
==Participants==\n\
*[[User:Leidenfrost|Leidenfrost]]\n\
*<!--[[User:π π π|π π π]]-->\n\
\n\
==Expedition==\n\
\n\
==Photos==\n\
<gallery>\n\
</gallery>\n\
\n\
==Ribbons==\n\
{{#vardefine:ribbonwidth|100%}}" + ribbonsTemplate + "\n\
\n\
__NOTOC__\n\
<!--\n\
[[Category:Expeditions]]\n\
[[Category:Coordinates reached]]\n\
[[Category:Coordinates not reached]]\n\
[[Category:Not reached - No public access]]\n\
[[Category:Not reached - Mother Nature]]\n\
[[Category:Expeditions with photos]]-->\n\
";

    $(document).ready(waitForWikiEditor);
}
// </includeonly>