Domanda

For many of the questions I find helpful on SO, I note the topic (question) ID in my notebook. The question ID (a number) is in the URL, but locating it in the browser address bar is error-prone if not inconvenient. How can I go about writing an add-on for Firefox that will somehow display the question ID prominently (in large font)?

Note: I am asking this question here because SO is the stackexchange site I use most frequently.

È stato utile?

Soluzione

There is no need for an add-on just to get the question ID. The following bookmarklet shows the question ID of the current question.

javascript:alert(StackExchange.question.getQuestionId());

I found this as follows:

  1. Show source (Ctrl + U in Firefox)

  2. Search for *17010194`, enable Highlight all

  3. Observe a line containing:

    StackExchange.question.init({votesCast:[],canViewVoteCounts:true,totalCommentCount:4,shownCommentCount:4,highlightColor:'#F4A83D',backgroundColor:'#FFF',questionId:17010194});

  4. Use Ctrl + Shift + K to open the Web console.

  5. Enter StackExchange.question and click on the result to inspect the object properties: inspect StackExchange.question

  6. Guess that StackExchange.question.getQuestionId is a function returning the question ID (type it in the Web Console).

  7. On observation that this works, put it in javascript:alert(...) and post an answer.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top