Page 1 of 1

[EOS/TOOL] EOS Magpie - Eos Script Merging Tool

Posted: Wed Jan 20, 2021 4:28 am
by fapnip
Here's my "Eos Magpie" tool for merging data from one Eos script to another:
https://codepen.io/fapnip/full/GRjwPXP

It's called Eos Magpie, because like a common myth surrounding the magpie, it lets you grab shiny things from Eos tease scripts.

Use it to copy data (pages, images, etc.) from one Eos script source, merge it with another, and download the merged JSON.

Let me know if you find it useful, or have issues. Built for my own use, but figured some of you may find it helpful.

(Updated to make it easier to recover images missing in target from a source that has one or more of the given images.)

Here's some things you can embed in your tease's Init Script to tell Eos Magpie what to do:

Name / Version of tease
So Magpie can know what your tease's name and version is, simply add the following to the start of your Init Script

Code: Select all

/************************
 * My Tease Name v1.2.3
 */
Display notice to users of Eos Magpie
To display a message to users of Eos Magpie that have entered your tease as the "source", add the following anywhere in your Init Script

Code: Select all

/*--magpie-warn
Please be nice and let me know if you're using my tease.
Thanks.
*/
Automatic updates
To tell Magpie to automatically select the init script and source pages that are different or missing in the target if the tease name for the source and target are the same, or if the target has an empty init script, add the following anywhere in your Init Script:
(If the page already exists in target, it WILL be marked for replacement.)

Code: Select all

/*--auto-magpie-core
my-page-that-should-be-updated
and-so-on
pages-names-*
*/
To tell Magpie to automatically select source pages that are missing in the target if the tease name for the source and target are the same, add the following anywhere in your Init Script:
(If the page already exists in target, it will NOT be marked for replacement.)

Code: Select all

/*--auto-magpie-require
my-page-that-is-needed
another-required-page
*/
Keeping an action from target when replacing page from source
To tell Magpie to keep changes in a specific action when updating a page, place an eval containing the --auto-magpie-merge:[unique-merge-id] tag right before the given action. (Note: Replace "[unique-merge-id]" with a unique (relative to page) string. This allows magpie to know which actions to merge in target and source.):

Code: Select all

/*--auto-magpie-merge:my-merge-id-1121 */
Now, the action immediately following the auto-magpie-merge eval tag in the target will not be overwritten with the same action from the source. Eval tag must exist in both source and target, and tag ids (the string following the ":") must be unique, relative to page. If not, you'll end up with a mess after merge.

Creating a "Magpie Module"
A Magpie Module is a group of actions and evals that can be shared with other tease authors, and allows them to easily install and update the module in their own teases using Magpie.

To create a module, add an IF action to you start page. In that if action, set the condition to something like:

Code: Select all

!window.MyMagpieModule /* MPEM::MyMagpieModule v1.0.0 */
Where "MyMagpieModule" is the unique name of your magpie module. (Make sure you're not conflicting with another Magpie module, or an existing JavaScript object.)

In the IF's actions, you must have, at a minimum, an Eval action that creates your Module's object/prototype. For example:

Code: Select all

// We always want to wrap in an immediate function to avoid global namespace pollution.
;(function(){
  // First some optional header information so Magpie can display things to users
  /***************************
  * MyMagpieModule
  ****************************
  MPED--author::My Milovana User Name
  MPED--description::
A description of an otherwise useless example Magpie Module, displayed in Magpie

See:
https://milovana.com/forum/posting.php?mode=edit&f=4&p=294482
  ::--description
  */

  // Now the real code for the Module
  if (window.MyMagpieModule) return // already installed.  Get out.
  // Define a constructor method for our module prototype
  funciton MyMagpieModule(opts) {
    // If we didn't get any options, make some default ones
    opts = opts || {
      name: 'Billy the Bob',
      level: 0,
    }
    this.name = opts.name
    this.level = opts.level || 0
  }
  
  // Create some methods
  MyMagpieModule.prototype.getName = function () {
    return this.name
  }
  MyMagpieModule.prototype.getLevel = function () {
    return this.level
  }
  MyMagpieModule.prototype.incrementLevel = function () {
    this.level++
  }
  
  // Export our module to the world
  window.MyMagpieModule = MyMagpieModule
  
})()
Now, after this useless example module has been loaded in the start page, it can be used like:

Code: Select all

// This module example uses a prototype, so we need to create an instance of it to use it.
if (!window.myUselessModuleInstance) {
  // We don't have a global instance built yet, so let's do that.
  window.myUselessModuleInstance = new MyMagpieModule({
    name: 'Super Fly',
    level: 2,
  })
}

// Now that we have an instance created, we can use it
console.log("Here's some useless information:", myUselessModuleInstance.getName(), myUselessModuleInstance.getLevel())
For an example of a real Magie Module that does something useful, see:
viewtopic.php?f=2&t=24275

Re: EOS Magpie - Eos Script Merging Tool

Posted: Wed Jan 20, 2021 7:00 am
by Roblsforbobls
Ok, now THAT is a good idea! Thanks for sharing :yes:

Re: EOS Magpie - Eos Script Merging Tool

Posted: Wed Jan 20, 2021 8:06 pm
by fapnip
Roblsforbobls wrote: Wed Jan 20, 2021 7:00 am Ok, now THAT is a good idea!
So all my other ideas are just chopped liver, eh? ;-)

(Eos Magpie has been updated with a few bug fixes/features.)

Re: EOS Magpie - Eos Script Merging Tool

Posted: Thu Jan 21, 2021 8:55 am
by Roblsforbobls
Nothing against liver lol

Re: EOS Magpie - Eos Script Merging Tool

Posted: Thu Jan 21, 2021 5:22 pm
by fapnip
Updated to allow tease JSON to be pulled from local JSON file as well as tease URL.

Re: EOS Magpie - Eos Script Merging Tool

Posted: Mon Jan 25, 2021 11:58 pm
by fapnip
Added /*--magpie-warn [your message] */ Init Script comment detection so tease authors can display a message to those using Eos Magpie to rip things from their tease.

Re: EOS Magpie - Eos Script Merging Tool

Posted: Wed Jan 27, 2021 3:06 pm
by fapnip
Fixed bug introduced in 0.2.7 that prevented download of merged script.

Re: [EOS/TOOL] EOS Magpie - Eos Script Merging Tool

Posted: Mon Mar 20, 2023 10:47 pm
by PowerBot
Thanks for this, huge help being able to transfer galleries and other content between teases!

Re: [EOS/TOOL] EOS Magpie - Eos Script Merging Tool

Posted: Fri Mar 08, 2024 5:16 pm
by Morexis
Is EOS Magpie broken or am I doing something wrong? Regardless which tease I enter, it always says "Unable to load tease URL" 😢

Image

Re: [EOS/TOOL] EOS Magpie - Eos Script Merging Tool

Posted: Fri Mar 08, 2024 7:24 pm
by indyc
Morexis wrote: Fri Mar 08, 2024 5:16 pm Is EOS Magpie broken or am I doing something wrong? Regardless which tease I enter, it always says "Unable to load tease URL" 😢

Image
If you download your json and click the attachment looking symbol on the right of where you paste the link you can upload the json file and it will work. (It used to work from both link and raw json but now only json works) Reach out to me if you need more help!