3

The website Quora blurs out most of its content if you're not logged in. One way around this is to add the parameter "?share=1" to its URL. I think the steps to doing this via Greasemonkey are:

0/ stash the current URL

1/ check to see if the parameter is already there. If it is, break.

2/ If not, add parameter.

3/ reload with updated URL.

It is similar to this question but it seems to me that this could be done without regex? I could be wrong.

This is the code I'm trying to use:

// ==UserScript==
// @name       Quora Share
// @namespace  kevmo.info
// @version    0.1
// @description  adds "?share=1" to URLS, i.e. let's you view full Quora content w/o being logged in.
// @include      https://*.quora.com/*
// @include      http://*quora.com/*
// @copyright  Creative Commons
// ==/UserScript==

var url = window.location.href;

if (url.indexOf("?share=1") !== -1){
    break;
}
else{
    url +="?share=1";
    window.location.replace(url)
}

Note: in "settings", i set the script to run at document-start.

I know that this sort of basic approach would not work on other websites, but merely appending "?share=1" should work on Quora (see: http://blog.quora.com/Making-Sharing-Better)

When I visit http://www.quora.com/Animals/What-are-some-mind-blowing-facts-from-the-animal-kingdom, the page does not reload with the desired new URL with the added parameter.

Community
  • 1
  • 1
kevmo
  • 677
  • 1
  • 8
  • 20
  • You don't want to just tack `?share=1` to the end of the URL because the URL may already have either URL parameters and/or a hash (`#`). Doing it this way would bust the URL. (Your current code would work if there was NEVER any other URL params or hashes.) Use the same kind of approach as in that question you linked. – Brock Adams Mar 06 '13 at 20:21
  • I believe this will work for Quora: http://blog.quora.com/Making-Sharing-Better – kevmo Mar 06 '13 at 20:42
  • Well you have the script in the question. Does it work? If not, how does it fail? If yes, or you haven't tried it, why the question? ... Finally even if it appears to work *now*, it **will** fail in some circumstances or when the site changes -- for the reasons I gave above. .. Don't reinvent the wheel without a damn good reason. The linked approach has been proven time and again and is designed with the structure of URL's in mind. – Brock Adams Mar 06 '13 at 20:56
  • Thanks for the insightful questions, Brock. I edited the question details to address them. – kevmo Mar 06 '13 at 21:11

1 Answers1

2

meta-edit: you're using "break;" while not in a looping structure.

    function share_redirect() {
    var new_url = false;

    if (window.location.hash.length === 0  && window.location.search.lenth === 0) {
         new_url = window.location.href+"?share=1"
    } else {

         if (window.location.search.indexOf('share=1') != -1) {
             return false; // already sharing
         }

         if (window.location.search.length && window.location.hash.length) {

             new_url = window.location.href.split('#')[0]+"&share=1"+window.location.hash;
         } else if (window.location.search.length === 0 && window.location.hash.length) {
             new_url = window.location.href.split('#')[0]+"?share=1"+window.location.hash;
         } else {
             new_url = window.location.href+"&share=1";
         }
    }
    if (new_url) {
        window.location = new_url;
    }
}
  • 1
    First line of condition has a spelling mistake - lenth for length. Could not correct as minimum 6 chars are required. Voted up. – Satya Prakash Jun 20 '13 at 07:06