New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort out selection tags #29

Closed
neocotic opened this Issue Aug 5, 2011 · 2 comments

Comments

Projects
None yet
1 participant
@neocotic
Member

neocotic commented Aug 5, 2011

As suggested by an anonymous user, I will add a tag that allows users iterate over any links in the current selection.

The suggested implementation is to add something like the following in to shortcuts.js (might want to renamed this to something more generic now - like content.js - ensuring manifest.json, background.js and Makefile are updated also);

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
    var anchors,
        data = {
            text: '',
            urls: []
        },
        contents,
        selection = window.getSelection();
    data.text = selection.toString();
    if (selection.rangeCount > 0) {
        contents = selection.getRangeAt(0).cloneContents();
        if (contents) {
            anchors = contents.querySelectorAll('a[href]');
            for (var i = 0; i < anchors.length; i++) {
                data.urls.push(anchors[i].getAttribute('href'));
            }
        }
    }
    sendResponse(data);
});

This will listen for a request from the background page that will be triggered when the user activates a template. This request will need to wrap the build*Data functions and requires the current tab;

chrome.tabs.sendRequest(tab.id, {}, function (response) {
    // Continue to build data...
});

Since I'm going to be making this request each time it's worthwhile getting the selected text at the same time (as implemented above) so users should also be able access the {selection} tag when using popup/shortcuts.

@ghost ghost assigned neocotic Aug 5, 2011

@neocotic

This comment has been minimized.

Show comment
Hide comment
@neocotic

neocotic Aug 5, 2011

Member

Calling the new complex type {selectionLinks} as it is basically just that.

Member

neocotic commented Aug 5, 2011

Calling the new complex type {selectionLinks} as it is basically just that.

neocotic added a commit that referenced this issue Aug 5, 2011

@neocotic

This comment has been minimized.

Show comment
Hide comment
@neocotic

neocotic Aug 5, 2011

Member

Will need to update the external guide for writing templates but this has now been implemented and might want to cover this in the FAQ.

Member

neocotic commented Aug 5, 2011

Will need to update the external guide for writing templates but this has now been implemented and might want to cover this in the FAQ.

@neocotic neocotic closed this Aug 5, 2011

@neocotic neocotic added the accepted label Nov 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment