Giter Site home page Giter Site logo

cantino / selectorgadget Goto Github PK

View Code? Open in Web Editor NEW
1.0K 49.0 182.0 4.66 MB

Go go CSS / DOM inspection.

Home Page: http://www.selectorgadget.com

License: MIT License

Ruby 0.15% Shell 0.07% CSS 2.30% JavaScript 48.33% CoffeeScript 4.63% HTML 44.01% SCSS 0.51%

selectorgadget's Introduction

SelectorGadget

SelectorGadget is an open source bookmarklet that makes CSS selector generation and discovery on complicated sites a breeze.

Please visit http://www.selectorgadget.com to try it out.

Technologies

Features

Remote interface

SelectorGadget can be extended for use in custom workflows with a remote interface that replaces the standard display and controls.

To define a remote interface, create a JavaScript file with any functionality you need, and append any relevant controls to SelectorGadget's UI container. Here's a simple example:

// sg_interface.js

var SG = window.selector_gadget

// Add field to display current selection (note the use of jQuerySG, 
// SelectorGadget's jQuery alias).
var path = jQuerySG('<input>', { id: 'sg-status', class: 'selectorgadget_ignore' })
SG.sg_div.append(path)
SG.path_output_field = path.get(0)

// Add button to dismiss SelectorGadget
var btnOk = jQuerySG('<button>', { id: 'sg-ok', class: 'selectorgadget_ignore' }).text('OK')
SG.sg_div.append(btnOk)
jQuerySG(btnOk).bind('click', function(event) {
  jQuerySG(SG).unbind()
  jQuerySG(SG.sg_div).unbind()
  SG.unbindAndRemoveInterface()
  SG = null
})

// Watch the input field for changes
var val = saved = path.val()
var tid = setInterval(function() {
  val = path.val()
  if(saved != val) {
    console.log('New path', val, 'matching', (jQuerySG(val).length), 'element(s)')
    saved = val
  }
}, 50)

Set the path to the remote interface in SelectorGadget's sg_options object prior to instantiation, like this:

window.sg_options = {
  remote_interface: '/path/to/sg_interface.js'
}

window.selector_gadget = new SelectorGadget()
// ...

Local Development

Compiling

Start by installing development dependencies with

bundle

and then run

guard

to watch and regenerate SelectorGadget's .coffee and .scss files.

Testing

SelectorGadget is tested with jasmine. With guard running, open spec/SpecRunner.html in your browser to run the tests. (On a Mac, just do open spec/SpecRunner.html)

To manually test during local development, open spec/test_sites/bookmarklet_local.html and use that local bookmarklet on the contents of spec/test_sites.

Bitdeli Badge

selectorgadget's People

Contributors

adamsanderson avatar bitdeli-chef avatar cantino avatar dortonway avatar eugeneotto avatar methuz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

selectorgadget's Issues

Yellow background is hard to see on a white background

Yellow background is hard to see on a white background. So what I did is changed the background-color for the selectorgadget_suggested css class to another color which had more contrast. It would be nice if the colors can be adjusted in the extension's UI.

won't work on Github Next

Thanks so much for your tool; it was part of my workflow to build my intro.js script.

Seems like it will not work on github.com at all, which makes me sad since I want to build a tutorial for their new Next interface in an hour or 2. It will load other sites just fine on my WIn7 Firefox20.

Update: Tested on Chrome Canary, on the "old Github" interface, not loged in; consistantly gets stuck at "Loading...", & will not load the bar on bottom. If you need me to check via DevTools/Firebug, please let me know.

cheers

How do I install this?

There are no instructions listed in the read me on how to install this...the read me file on github...points to the website for info on how to install it....the website...of course...points to the github account...which point to the website...which...oh you you git now.

Question !

I know the bookmarklet has been ported to Chrome so do you intend to port it to Firefox too ?

Best Regards ! ๐Ÿ˜„

What is ":content" in output?

I've got this selector: ":content("Website:")+ .fl_l a" here https://vk.com/dorton

So I can't use it in jQuery (after injecting jQuery into this page) because of this error:
Error: Syntax error, unrecognized expression: unsupported pseudo: content

Problem with F6s.com

SelectorGadget is not working at F6s.com (for example https://www.f6s.com/newhaircut ). It's because it's doing split on svg className, which is not a string. I solved it by changing line 7018 at selectorgadget_combined.js from:

if (node.className) {

to

if (node.className && typeof node.className.split !== 'undefined') {

But don't have time to do a pull request, sorry.

Unable to compile

I've modified Coffee files in lib/js/core and started guard but nothing happens, files in build/ were not updated.

TypeError: node.className.split is not a function

Happens when selecting an SVG.

TypeError: node.className.split is not a function
    at window.DomPredictionHelper.DomPredictionHelper.cssDescriptor (selectorgadget_combined.js:11018:33)
    at window.DomPredictionHelper.DomPredictionHelper.pathOf (selectorgadget_combined.js:10998:30)
    at window.DomPredictionHelper.DomPredictionHelper.getPathsFor (selectorgadget_combined.js:11311:25)
    at window.DomPredictionHelper.DomPredictionHelper.predictCss (selectorgadget_combined.js:11322:29)
    at window.SelectorGadget.SelectorGadget.sgMousedown (selectorgadget_combined.js:11760:45)
    at HTMLDivElement.dispatch (selectorgadget_combined.js:5430:27)
    at elemData.handle (selectorgadget_combined.js:5234:28)

When I check node.className it is not a string but an instance of SVGAnimatedString.

e.className.split is not a function

Hi @cantino thanks for amazing tool. But, I think it require some bug fixes or upgrade. As, I've been running some test cases and found that SG doesn't works in few sites and throw this error:

combined.js:22 Uncaught TypeError: e.className.split is not a function

For example : See this error on below URL and as I click on any element on body, it errors and doesn't return and selector

https://www.yellowpages.com/washington-dc/mip/usa-guided-tours-483856541?lid=1001440551023

image

Generate a maximum CSS selector

Hello Guys, awesome work on your tool!
It came to me though that I am missing out on the feature of being able to select not only the minimal DOM element but also the exact one, determined by the containing text and type.
This would be great for a plugin that I am working on which lets a chrome user add/attach a hotkey to an arbitrary button or link on a specified website.
Of course i can add all the required selectors to resolve the specific element by hand but it would be great if I had a smart assistant library that can do that for me.
Any thoughts on this?

Cheers, keep it up!

Complex selectors in :not pseudoselector

I'm not sure if this is a bug or a feature, but I'd love to know how SelectorGadget manages to allow complex selectors inside the :not pseudoselector.

For example, from this html:

  <h2 id="heading1'> This is Heading 1 </h2>
  <p> Some text in section1 </p>
  <p> Some more text in section 1 </p>
  <ul>
      <li> Some random list in Section 1 </li>
 </ul>
 <h2 id="heading2"> This is Heading 2 </h2>
 <p> Some text in section 2 </p>
 <p> Some more text in section 2 </p>

I can give SelectorGadget the following CSS:

h2:contains("Heading 1") ~ *:not(h2:contains("Heading 2") ~ *)

And get all the nodes in between the 2 h2 elements (with the second h2 as well). My understanding of the CSS specification is that the :not pseudoselector shouldn't allow this, and when I try using this selector elsewhere, it won't work.

When I try to get an Xpath for that selector, I get the following from SelectorGadget:

//h2//1')//~//*//2')//~//*)

And this doesn't even look like valid Xpath.

That said, I would really like to be able to select all the sibling nodes between any 2 arbitrary nodes. Is there a library or CSS specification that SelectorGadget uses to do this?

Selector h4+ p is incorrectly translated to xpath

On the page https://www.kpu.ca/calendar/2018-19/courses/jrnl/index.html, I'm trying to select the paragraph of course description that follows each course title. For example, "Students will explore how journalism fits in a media landscape..."

I can successfully highlight the appropriate elements in SG by clicking on this paragraph, then clicking on one of the "Prerequisites" elements to prevent them from being included. This results in the correct CSS selector h4+ p

However, when I translate this to an Xpath, I get //h4+//p which is not correct. I would expect this to translate to something like //h4/following::p[1], which gives the correct result.

We have been advising people to use SelectorGadget to write the expressions for the Xpath Extractor in Workbench (http://help.workbenchdata.com/steps/scrape/xpath-extractor) as a way to avoid learning the xpath syntax, so it's unfortunate that this case is mis-translated.

SG updates

Hi Andrew,

SG is super useful tool as you know already. I noticed it's not update for quite some time. Can you be honest and tell me if you have somethings on your mind which you think it need to be added to SG to make his functionality even deeper. Or do you know even other/similar tool which do same with more functionality or which have something wich SG doesn't have.

Also, do you have plans on updating SG, and if yes can u share ur vision ?

Peace,

See impact on multiple pages

I have struggled with css selectors and tried many many tools - this is hands down the most useful I've found! I'm do drupal site building and often need to tweak css. Trouble is that selector only targets a page and not the site. any chance that can be accommodated? Please continue development of this - it's wonderful!

Invalid selector when handling colons in class names

I could only find this on the CVS Extracare page because I do not know of other pages that might use colons in class names. However, attempting to select the container of the coupon cards shows a CSS selector of .md\:tw-justify-between:nth-child(5). If you try to use it in querySelector, it errors with Uncaught DOMException: Document.querySelector: '.md:tw-justify-between:nth-child(5)' is not a valid selector. This is caused by the \: not being properly escaped as \\:.

Version: Bookmark (August 7, 2013)
Browser version: Firefox 125.0.3 (64-bit)
OS: macOS Monterey 12.0.1

Screen Shot 2024-05-06 at 11 03 57 AM

Reproduction shown below:
https://github.com/cantino/selectorgadget/assets/33487725/2224a6d5-c1cd-4827-b33c-a5b465e56536

how to prevent clicks from bubbling

Hi, I was wondering how you guys are able to catch click events and prevent them from propagating? I'm trying to build a Chrome extension that has some similar function and I need to prevent any clicks events from my own event handler.

Examples of extending SelectorGadget

It isn't really clear how to use SelectorGadget as a library, instead of a full featured bookmarklet.

Specifically I want to build a more advanced workflow around the SelectorGadget functionality. I saw that you mention "Remote Interfaces", but I couldn't figure them out. Could you provide an example of an HTML page with the necessary script dependencies to do a Remote Interface?

Publish your extension to Microsoft Edge Addons website

Microsoft Edge is the second most used browser on the web, making the browsing experience more flexible, offering many more services for users and optimized for Windows devices.

Microsoft Edge supports Chromium extensions, and you can publish your extensions to Microsoft Edge Add-ons website with minimal code changes. Find out more here.

If you have any more queries about porting Chrome extension to Microsoft Edge or anything else, you can contact the relevant teams whose links are given here.

Let me know if this was helpful. I am happy to help you with more details.

Selecting list of objects

This is a pretty awesome tool to get the css selectors / xpath for the elements. I have a use case for which I might need to extend how selectorgadget works.

When there's a listing page, like hacker news (https://news.ycombinator.com/), and if we need to be able to choose multiple fields, the "null" values get left out. Like if a particular post does not have points or link, I need to be able to group them by a parent DOM - or find a common dom between the fields chosen.

Any suggestion on how this can be done? Or if Selector gadget has a mode supporting this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.