question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regarding the use of the property `"g"` (for gallery rules)

See original GitHub issue

Greetings

For reference, the relevant lines the script are from line 933 to 974.

This property was not documented by the original MPIV author in his How to add more rules so I had asked a lot time ago in the greasyfork page https://greasyfork.org/en/forum/discussion/4551/x and someone had kindly described me the following:

Click to expand

kuehlschrank Probably didn’t get the time to do that so until then I’ll tell you few things I picked, mostly from wOxxOm :

  1. "g" rule is similar to "q" rule plus the ability to return multiple photos
  2. Have the variable text (raw HTTP response / source code of HTML page)
  3. Also you can manage to have the other two variables node and doc* *(Firefox only)

Methods

  1. Simple selectors "g":{"entry":".main","title":".h1","caption":".info","image":".photo","fix":"return s"}

    • "entry": used to select main blocks that contain the photos and their captions
    • "title": (pick text) would show up on the first photo
    • "caption": (pick text) for each photo
    • "image": photos
    • "fix": used to clean the output

    All are optional except "image"

  2. Using array "g":"g=[]; r=/regex/g; while(m=r.exec(text)) g.push({url:m}); return g"}

    • Creating a regex and have it run on variable text then push photos to g
  3. On Firefox you can create a doc of the raw text doc=createDoc(text) to select from it by doc.querySelector('')


Are the above still valid in this fork?

And, I have some more questions:

  • He said that this "g" rule is similar to "q" rule. Does this mean that this "g" property is only applied to the remote page? Can we not use it in the currently loaded page, if it’s a gallery itself and contains all the next/previous full image URLs ? If yes, can this be done via the “array” syntax: "g":"g=[]; r=/regex/g; while(m=r.exec(text)) g.push({url:m}); return g"} ?
  • in the “simpler” syntax:
    {"d": "example.com",
     "g": {
      "entry": ".main",
      "title": ".h1",
      "caption": ".info",
      "image": ".photo",
      "fix": "return s"
     }
    }
    
    what is the s in "fix" ? And, the "entry" selector refers to the initial page holding the gallery thumbnail, while the "image" selector, refers to the remote page?
  • Can I use node (element that triggered popup) and doc (dom tree of remote page) ? How? Is it still Firefox only?

Thank you

PS. Sorry for the lengthy post!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:43 (21 by maintainers)

github_iconTop GitHub Comments

2reactions
tophfcommented, Dec 13, 2020

You need to make g a function for MPIV so it’d be something like rule.g = "var g=.......; return g"

2reactions
tophfcommented, Apr 2, 2020

I’ve updated mpiv and now you can write it like this:

{"d": "twilightsite.com",
 "e": "td > a:first-child",
 "s": "gallery",
 "g": "var g=[...document.querySelectorAll(rule.e)].map(_=>({url:_.href})); g.index=node.href; return g"
}
{"d": "twilightsite.com",
 "e": "td > a:first-child",
 "s": "gallery",
 "g": {
  "image": "td > a:first-child",
  "index": "return node.href"
 }
}

This works only if index is set to a URL that exactly equals to one of the items so in a more generic case you would have to determine the index using the standard JS array methods or any other means.

Read more comments on GitHub >

github_iconTop Results From Across the Web

2023 Code of Ethics & Standards of Practice
REALTORS® should recognize that the interests of the nation and its citizens require the highest and best use of the land and the...
Read more >
Fair Use (FAQ) - U.S. Copyright Office
Under the fair use doctrine of the U.S. copyright statute, it is permissible to use limited portions of a work including quotes, for...
Read more >
Appendix G to Part 1026 — Open-End Model Forms and ...
G -3 - Long-Form Billing-Error Rights Model Form (Home-Equity Plans). YOUR BILLING RIGHTS. KEEP THIS NOTICE FOR FUTURE USE. This notice contains important ......
Read more >
Part 13 - Simplified Acquisition Procedures
(g) Authorized individuals shall make purchases in the simplified manner that is most suitable, efficient, and economical based on the circumstances of each ......
Read more >
U.S. Government Works | USAGov
Images. To ensure that you don't use protected intellectual property, check with the agency or program that manages the website.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found